如何在Spring中连接代理对象?
我正在使用带有属性可选传输协议的代理 bean。我的问题是bean属性无法转换,但我真的不知道为什么。情况是这样的:
我的属性:service.protocol=rmi
<!-- This is the 'multiplexing' factory bean (using this because properties
cannot be used in bean names and aliases -->
<bean name="dbFormGenWindowComponent"
class="org.springframework.beans.factory.config.BeanReferenceFactoryBean">
<property name="targetBeanName" value="dbFormGenWindowComponent-${service.protocol}invoker" />
</bean>
<!-- Here are the service invoker beans with two protocols: -->
<bean name="dbFormGenWindowComponent-rmiinvoker" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="${ringwindow.serviceURL.rmi}/${ringwindow.service.name}-dbFormGenWindowComponent"/>
<property name="serviceInterface" value="foo.bar.service.formgen.windows.FormGenWindowComponent" />
<property name="lookupStubOnStartup" value="false"/>
</bean>
启动时的异常是:
org.springframework.beans.TypeMismatchException: 无法转换属性值 输入 [$Proxy541] 到所需类型 [foo.bar.service.formgen.windows.FormGenWindowComponent] 对于属性“formGenWindowComponent”; 嵌套异常是 java.lang.IllegalArgumentException: 无法转换类型值 [$Proxy541] 为所需类型 [foo.bar.service.formgen.windows.FormGenWindowComponent] 对于属性“formGenWindowComponent”: 没有匹配的编辑器或转换 找到策略
我认为嵌套工厂 bean 应该可以正常工作。您知道如何完成这项工作吗?
I am using proxy beans with property-selectable transport protocol. My problem is that bean properties cannot be converted, but I really don't know why. This is the situation:
My property: service.protocol=rmi
<!-- This is the 'multiplexing' factory bean (using this because properties
cannot be used in bean names and aliases -->
<bean name="dbFormGenWindowComponent"
class="org.springframework.beans.factory.config.BeanReferenceFactoryBean">
<property name="targetBeanName" value="dbFormGenWindowComponent-${service.protocol}invoker" />
</bean>
<!-- Here are the service invoker beans with two protocols: -->
<bean name="dbFormGenWindowComponent-rmiinvoker" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="${ringwindow.serviceURL.rmi}/${ringwindow.service.name}-dbFormGenWindowComponent"/>
<property name="serviceInterface" value="foo.bar.service.formgen.windows.FormGenWindowComponent" />
<property name="lookupStubOnStartup" value="false"/>
</bean>
The exception on startup is:
org.springframework.beans.TypeMismatchException:
Failed to convert property value of
type [$Proxy541] to required type
[foo.bar.service.formgen.windows.FormGenWindowComponent]
for property 'formGenWindowComponent';
nested exception is
java.lang.IllegalArgumentException:
Cannot convert value of type
[$Proxy541] to required type
[foo.bar.service.formgen.windows.FormGenWindowComponent]
for property 'formGenWindowComponent':
no matching editors or conversion
strategy found
I think nested factory beans should work fine. Do you have any idea how to get this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将注入点类型定义为具体类而不是接口,但您是基于接口进行代理时,通常会发生这种情况。例如:
对于工厂 bean,这可能是由于工厂 bean 的返回类型被定义为具体类。如果你不能改变类中的任何内容,你可以配置 spring 使用 cglib-proxying,通过:
- 在 bean 定义中 - 这将配置bean
- 全局更改此设置This usually happens when you have defined your injection point types to be concrete classes, rather than interfaces, but you are proxying based on interface. For example:
In the case of factory beans this may be due to the factory bean's return type being defined as a concrete class. If you can't change anything in the classes, you can configure spring to use cglib-proxying, by:
<aop:scoped-proxy>
- inside a bean definition - this will configure proxies of the bean<aop:aspectj-autoproxy proxy-target-class="true">
- changes this globally