java - Make all Spring beans of a certain type request scoped -
i have class , want objects of type request scoped. in spring xml, i'm creating list of such objects. it's tedious , error-prone have set scope , proxy mode each 1 of these beans, there way make beans of type request scoped automatically?
i tried annotating class @scope(value = webapplicationcontext.scope_request, proxymode = scopedproxymode.target_class)
didn't seem work. maybe annotation ignored when bean created via xml?
here's have far in xml:
<util:list> <bean class="com.test.myclass" scope="request"> <aop:scoped-proxy/> <constructor-arg> <bean value="hello"/> </constructor-arg> </bean> <bean class="com.test.myclass" scope="request"> <aop:scoped-proxy/> <constructor-arg> <bean value="friend"/> </constructor-arg> </bean> </util:list>
and class:
public class myclass { private string value; public myclass() { /* default constructor */ } public myclass(string value) { this.value = value; }
basically wondering if there way can avoid having add scope="request"
, <aop:scoped-proxy/>
every bean of type myclass , have them request scoped automatically.
you might try annotate class @component in addition @scope. need add configuration class @configuration , @componentscan within package allow scanning of component.
Comments
Post a Comment