Java 如何在spring中连接代理对象?
我正在使用具有属性可选传输协议的代理bean。我的问题是bean属性无法转换,但我真的不知道为什么。情况就是这样: 我的属性:service.protocol=rmiJava 如何在spring中连接代理对象?,java,spring,rmi,Java,Spring,Rmi,我正在使用具有属性可选传输协议的代理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="dbFormGenWindowCompo
<!-- 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应该可以正常工作。您知道如何完成这项工作吗?当您将注入点类型定义为具体的类而不是接口时,通常会发生这种情况,但您是基于接口代理的。例如:
public interface Foo { .. }
public class FooImpl { .. } // this is declared as bean
public class Bar {
private FooImpl foo; // this fails
private Foo foo; // correct way
}
对于工厂bean,这可能是因为工厂bean的返回类型被定义为一个具体的类。如果不能更改类中的任何内容,可以通过以下方式将spring配置为使用cglib代理:
-在bean定义中-这将配置bean的代理
-对其进行全局更改