在我的配置的spring/resources.xml文件中,我定义了一个bean,如下所示:
<bean id="myService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://${remote.host}:8080/MyAgent/remoting/MyService"/>
<property name="serviceInterface" value="services.MyService"/>
</bean>在我的Config.groovy文件中有: remote.host = "someipaddress“
现在我想在运行时更改这个占位符的值。在一个常规的spring应用程序中,我通过一个PropertyPlaceHolderConfigurer来做这件事,然后我刷新上下文,它就能工作了。
在Grails中,如何刷新上下文?
致以敬意,
菲利普
发布于 2010-12-01 02:32:49
好吧,我放弃刷新方法。作为一种解决办法,我创建了一个grails服务,如下所示:
class myService {
def myRemoteService
static transactional = false
private MyRemoteService getService(String remoteServiceURL) {
HessianProxyFactory factory = new HessianProxyFactory();
try {
return (MyRemoteService) factory.create(MyRemoteService.class, url);
}
catch (MalformedURLException e) {
e.printStackTrace()
}
return null
}
def someRemoteMethod(String remoteServiceURL) {
getService(remoteServiceURL).myRemoteMethod()
}
}这允许我动态地调用任何远程机器上的远程服务。
我仍然对更干净的解决方案感兴趣,因为这会让我为每个远程方法重写一个包装器方法:-S
发布于 2010-11-26 10:38:09
为什么不直接更新值:
def blabla
...
void someServiceMethod() {
blabla.someProperty = 'new value'
}或
def blabla
...
def someControllerAction = {
blabla.someProperty = 'new value'
}发布于 2010-11-26 19:06:17
grailsApplication公开了一个refresh()方法,我不确定它是否会重新加载spring上下文,你可以试试。
https://stackoverflow.com/questions/4280056
复制相似问题