java - How to handle custom autowired objects in Spring 2.5? -


i have old project need integrate spring 2.5.x (3.0 not possible).

i have created bean, have initializate field usersession itself:

public class somebean {     usersession usersession;      @postcontrust     public void init() {         httpsession session = webcontext.current().getsession();         usersession = (usersession) session.getattribute("usersession");     } } 

is possible write kind of autowiring handler resolve usersession , pass autowiring spring, bean looks like:

public class somebean {     @autowire usersession usersession; } 

and handler like:

public class autowirehanlder {     public boolean iscandidate(class<?> type) {         return type.equals(usersession.class);     }      public object resolve(class<?> type) {         httpsession session = webcontext.current().getsession();         return (usersession) session.getattribute("usersession");     } } 

i using session-scoped factorybean:

public class usersessionfactorybean extends abstractfactorybean<usersession> {      @override     public class<?> getobjecttype() {         return usersession.class;     }      @override     protected usersession createinstance() throws exception {         httpsession session = webcontext.current().getsession();         return (usersession) session.getattribute("usersession");        }  } 

define usersessionfactorybean bean:

<bean scope="session" class="com.xyz.usersessionfactorybean"/> 

... , should able autowire usersession other bean.

the complexity here usersessionfactorybean has session-scoped (see docs on bean scopes), since must return new value each httpsession. means bean autowired must also session-scoped, otherwise it'll fail. can around restriction using scoped-proxies.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -