我正在尝试在旧式 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/