问题
How can I go about setting the scope:
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")
in XML, instead of using @Scope
annotation?
回答1:
If you want XML based configuration then you can do it in following way:-
<bean id="YOUR_BEAN_ID" class="YOUR_FULLY_QUALIFIED_CLASSNAME" scope="prototype">
<aop:scoped-proxy proxy-target-class="true"/>
</bean>
回答2:
You can include Bean definition in xml file as below
<bean id="Simple" class="com.example.Simple" scope="prototype" />
来源:https://stackoverflow.com/questions/32780604/how-to-set-spring-scope-in-xml