Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing Grails applicationContext

In my configuration's spring/resources.xml file, I define a bean like this :

<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>

In my Config.groovy file I have : remote.host = "someipaddress"

Now I'd like to change this placeholder's value at runtime. In a regular spring app, I do this through a PropertyPlaceHolderConfigurer, then I refresh the context and it works.

In Grails, how can I refresh the context ?

Regards,

Philippe

like image 895
Philippe Avatar asked Apr 29 '26 23:04

Philippe


1 Answers

Ok I give up the refreshing approach. As a workaround, I created a grails service that looks like this :

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()
    }
}

This allows me to invoke the remote service on any distant machine dinamically.

I'm still interested in a cleaner solution as this makes me rewrite a wrapper method for each remote method :-S

like image 180
Philippe Avatar answered May 01 '26 11:05

Philippe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!