【问题标题】:How to set Spring Scope in XML如何在 XML 中设置 Spring Scope
【发布时间】:2015-09-25 10:54:52
【问题描述】:

如何设置范围:

@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")

在 XML 中,而不是使用 @Scope 注释?

【问题讨论】:

    标签: java spring proxy scope


    【解决方案1】:

    如果你想要基于 XML 的配置,那么你可以通过以下方式进行:-

    <bean id="YOUR_BEAN_ID" class="YOUR_FULLY_QUALIFIED_CLASSNAME" scope="prototype">
        <aop:scoped-proxy proxy-target-class="true"/>
    </bean>
    

    【讨论】:

      【解决方案2】:

      您可以在 xml 文件中包含 Bean 定义,如下所示

      <bean id="Simple" class="com.example.Simple" scope="prototype" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-15
        • 2017-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-25
        • 2016-04-20
        相关资源
        最近更新 更多