简体   繁体   English

无法从Config.groovy访问外部化的grails.serverURL

[英]Externalized grails.serverURL not accessible from Config.groovy

I have an application where the config is externalized. 我有一个配置被外部化的应用程序。 In Config.groovy, I'm updating 在Config.groovy中,我正在更新

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: 但是稍后在Config.groovy中,我有:

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. $ {grails.serverURL}包含[:],这不是我的配置文件中的内容。 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. 我的猜测是,仅当我从Config.groovy返回后,才使用更新的grails.config.locations。

So, what are my options to setup my web service details based on the externalized serverURL ? 那么,根据外部化的serverURL设置Web服务详细信息有哪些选择?

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. 就像您说的那样,Config.groovy看不到在外部配置中设置的值。 I believe that Grails processes external configs after Config.groovy, and this test appears to confirm that. 我相信Grails在Config.groovy之后会处理外部配置,并且该测试似乎可以确认这一点。 The logic being that you likely have external config file values that you want to have precedence over config in war file. 逻辑上是您可能具有要优先于war文件中的config的外部配置文件值。

Fix is to override the full property in myapp-config.properties: 解决方法是覆盖myapp-config.properties中的full属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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