开发者

Externalized grails.serverURL not accessible from Config.groovy

I have an application where the config is externalized. In Config.groovy, I'm updating

grails.config.locations=[file:/.../myapp-log4j.groovy, file:/.../myapp-config.properties]

That works fine for datasources and such. But later in Config.groovy, I have:

springws {
    wsdl {
        MyApp {
            // In this case the wsdl will be available at    <grails.serverURL>/services/v1/myapp/myapp-v1.wsdl
            wsdlName= 'myapp-v1'
            xsds= '/WEB-INF/myapp.xsd'
            portTypeName = 'myappPort'
            serviceName = 'myappService'
            locationUri = "${grails.serverURL}/services/v1/myapp"
            targetNamespace = 'http://www..../myapp/v1/definitions'
        }
    }
}

And ${grails.serverURL} contains [:] which is not what is in my config file. The config file contains (among the datasource details):

grails.serverURL=http://samiel:9011/xid

My guess开发者_开发技巧 would be that the updated grails.config.locations is only used after I return from Config.groovy.

So, what are my options to setup my web service details based on the externalized serverURL ?


This is what I get when I run your example (just confirming your starting postion):

def testExternalConfig() {
  println "grails.serverURL: ${ConfigurationHolder.config.grails.serverURL}"
  println "springws.wsdl.MyApp.locationUri ${ConfigurationHolder.config.springws.wsdl.MyApp.locationUri}"
}

--Output from testExternalConfig--
grails.serverURL: http://samiel:9011/xid
springws.wsdl.MyApp.locationUri http://localhost:8080/soGrails/services/v1/myapp

Like you said, Config.groovy does not see the value set in the external config. I believe that Grails processes external configs after Config.groovy, and this test appears to confirm that. The logic being that you likely have external config file values that you want to have precedence over config in war file.

Fix is to override the full property in myapp-config.properties:

grails.serverURL=http://samiel:9011/xid
springws.wsdl.MyApp.locationUri=http://samiel:9011/xid/services/v1/myapp

With that change I get this:

--Output from testExternalConfig--
grails.serverURL: http://samiel:9011/xid
springws.wsdl.MyApp.locationUri http://samiel:9011/xid/services/v1/myapp
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜