Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在spring中连接代理对象?_Java_Spring_Rmi - Fatal编程技术网

Java 如何在spring中连接代理对象?

Java 如何在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

我正在使用具有属性可选传输协议的代理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应该可以正常工作。您知道如何完成这项工作吗?

当您将注入点类型定义为具体的类而不是接口时,通常会发生这种情况,但您是基于接口代理的。例如:

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的代理
  • -对其进行全局更改

我检查了您提到的内容,我的代理是接口的代理,它们插入的bean也声明了接口的getter/setter。。然而,在检查这一点时,我发现我所有的BeanReferenceFactoryBeans都指向同一个代理,这才是真正的问题。我应该注意到所有ClassCastException都抱怨同一个编号的代理对象..:-(谢谢你对波佐的帮助!