gpt4 book ai didi

Spring 3.0 RmiProxyFactoryBean : how to change serviceUrl at runtime?

转载 作者:行者123 更新时间:2023-12-05 01:17:38 27 4
gpt4 key购买 nike

我有一个像这样的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 定义而不是手动实例化 RmiProxyFactoryBean 来更改“serviceUrl”参数?

最佳答案

获取 FactoryBean实例而不是工厂创建的 bean,使用 BeanFactory.FACTORY_BEAN_PREFIX . IE
RmiProxyFactoryBean rpfb = (RmiProxyFactoryBean) contex.getBean("&myService");

关于Spring 3.0 RmiProxyFactoryBean : how to change serviceUrl at runtime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10503769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com