2014-06-19 67 views
0

这个配置的问题可能会导致异常?为一个bean创建一个会话范围的代理

java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.testProxy': Target type could not be determined at the time of proxy creation.

<bean id="test" class="com.testsession.Test" scope="prototype" /> 

<bean id="testProxy" class="org.springframework.aop.framework.ProxyFactoryBean" scope="session"> 
    <property name="target" ref="test" /> 
    <property name="proxyInterfaces"><value>com.testsession.TestIface</value></property> 
    <aop:scoped-proxy/> 
</bean> 

testProxy的豆通过会话范围MVC控制器请求。是不是proxyInterfaces属性中指定的目标类型?

回答

2

你在你的概念在这里混了 - 你要么使用aop:scoped-proxy您提供一个明确的ProxyFactoryBean与适当的设置,而不是两个。

要使用aop:scoped-proxy

<bean id="testProxy" class="com.testsession.Test" scope="session"> 
    <aop:scoped-proxy /> 
</bean> 

要配置代理bean明确:

<bean id="test" class="com.testsession.Test" scope="session" /> 

<bean id="testProxy" class="org.springframework.aop.scope.ScopedProxyFactoryBean"> 
    <property name="targetBeanName" value="test" /> 
</bean> 

注意,代理配置了目标bean ,而不是实际的目标参考豆。

+0

谢谢。我使用ProxyFactoryBean的原因是我需要修改Test bean(实际上是JaxWsPortProxyFactoryBean),使用拦截器(可以在BindingProvider中放入用户名/密码)。你能告诉我如何使用你提供的样品吗? – Industrious

+0

@Industrious我已经添加了如何显式配置代理的示例,而不使用'aop:scoped-proxy' –