日期:2014-05-19  浏览次数:20688 次

spring在使用RMI时碰到一个问题,求解答。客户端方面的。
首先贴出客户端方面的BEAN配置信息:
 
XML code
    <bean id="helloService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 
        <property name="serviceUrl" value="rmi://192.168.0.109:1099/helloService"/> 
        <property name="serviceInterface" value="com.rmiClient.HelloWorldInterface"/> 
        <!-- setting refresh connect -->  
        <property name="refreshStubOnConnectFailure" value="true"></property>  
        <property name="lookupStubOnStartup" value="false"></property>  
    </bean> 



  我想做的是,动态修改serviceUrl的地址,也就是存在多个服务的情况下,我必须修改地址,然后调用其相应的远程服务。在测试例子中,这样做是可以的:
 
Java code
ApplicationContext context = new ClassPathXmlApplicationContext("xpring.xml");
        RmiProxyFactoryBean helloService = (RmiProxyFactoryBean)context.getBean("&helloService");

这样可以获得其代理对象,然后setServiceUrl()改变调用RMI地址。

  但如果我是注入在业务BEAN里面,该怎么获取呢?例如:
 
Java code
public class ABusinessService {
    
    @Autowired(required=true)
    private RmiProxyFactoryBean helloService;
    
    public String execute(){
        return helloService.getServiceUrl();
    }
}


 然后尝试
Java code
ApplicationContext context = new ClassPathXmlApplicationContext("xpring.xml");
ABusinessService a = (ABusinessService)context.getBean("businessService");
        System.out.println(a.execute());

执行到execute()后,报空指针了。很显然,在业务类中注入的helloService没有被实例化或者干脆不存在。而在实际项目中,请问应该怎样进行注入才能有(RmiProxyFactoryBean)context.getBean("&helloService");等同这样的效果。 希望我说得大家能明白。

------解决方案--------------------
<bean id="helloService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 修改里面的class啊
------解决方案--------------------
我上面的看错了,是不是没有get/set方法