简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM