How to set Spring Scope in XML

前提是你 提交于 2020-01-14 13:51:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!