xml - @Scope ( INTERFACES ) 相当于 XML

标签 xml spring annotations scope request

我正在尝试在旧式 xml 中执行此操作(代码)。

@Bean
    @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)   
    public MyInterface createInterface() {
        return connectionRepository().getPrimaryConnection(MyInterface.class);
    }

我尝试这样做:

    <bean id="myBean" class="a.b.c.MyInterface"
        factory-bean="myFactory" factory-method="create"
        scope="request">
        <constructor-arg value="a.b.c.MyInterface"></constructor-arg>
        <aop:scoped-proxy proxy-target-class="false"/>
    </bean>

但是我得到了:

Cannot convert value of type [$Proxy12 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [a.b.c.MyInterface] for property 'myBean': no matching editors or conversion strategy found

有什么想法吗? 谢谢!

最佳答案

这就是我最终让它工作的方法。斯卡夫曼挖得很近:

<bean id="factory"
    class="a.b.c.Factory"
    scope="request">
</bean>

<bean id="facebook" class="a.b.c.MyInterface"
    factory-bean="factory" factory-method="createObject"
    scope="request">
    <aop:scoped-proxy proxy-target-class="false"/>
</bean>

关于xml - @Scope ( INTERFACES ) 相当于 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8123557/

相关文章:

java - 在 MVC 应用程序中,依赖注入(inject)将在哪里发生?

java - 方法级别 Spring Security 的重要性

android - Dagger 2 : No implementation generated for component interface

java - RuntimeVisibleAnnotations 和 RuntimeInvisibleAnnotations - 如何从代码访问?

java - 如何使用 Java 从 URL 读取/获取 XML 文件?

php - 如何使用 Codeigniter 在浏览器中查看 XML 文件

xml - hibernate 一对多列表映射错误

java - 相当于 Struts 2 Preparable 的 Spring MVC

python - mypy:基类没有属性x,如何在基类中输入提示

php - SimpleXML 获取节点值