我有这样的bean定义:
<bean id="myService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="org.myapp.MyService"/>
<property name="serviceUrl" value="rmi://localhost:1099/myService"/>
</bean>
我以这种方式检索服务bean:
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:rmi-client-config.xml");
MyService myService = context.getBean("myService", MyService.class);
当然它返回一个“MyService”impl的实例,而不是RmiProxyFactoryBean。
那么如何使用上面的xml定义更改“serviceUrl”参数而不是手动实例化RmiProxyFactoryBean?
答案 0 :(得分:2)
要获取FactoryBean
实例而不是工厂创建的bean,请使用BeanFactory.FACTORY_BEAN_PREFIX
。即
RmiProxyFactoryBean rpfb = (RmiProxyFactoryBean) contex.getBean("&myService");