English 中文(简体)
是否可能从铁路外部化的汇合文档中装载更多的集束文档?
原标题:Is it possible to load more config files from an externalized config file in Grails?

假设情况:

I have downloaded a Grails application from the web as a WAR file, foo.war. In the documentation it says that I can put my own custom configuration in /foo.groovy, because this path is included in grails.config.locations in Config.groovy. I can dump all my custom config in that one file and life is good.

How, here s my problem... The configuration for FooApp is big and hairy, and I don t want it all in one file. I would like to break it up into /bar.groovy and /baz.groovy to keep things organized. Is there a way to specify something in /foo.groovy so that FooApp will also pick up /bar.groovy and /baz.groovy and process them?

I already tried appending paths to grails.config.locations in /foo.groovy, but Grails didn t like that and threw a nasty exception on startup. I m not sure what other approach to take.

明确:

grails-app/conf/Config.groovy looks:

grails.config.locations = ["file:/foo.groovy"]

现在,如果不修改<条码>grails-app/conf/Config.groovy,而且只能通过修改<条码>/foo.groovy,是否可装上除<条码>/foo.groovy以外的更多集束文档?

问题回答

您可在foo.groovy内补充编织文件:

foo.groovy

port {
  to {
    somewhere=8080
    another {
      place=7070
    }  
  }  
}
host = new ConfigSlurper().parse(new File("bar.groovy").toURL())

bar.groovy

to {
  somewhere="http://localhost/"
  another {
    place="https://another.place.com/"
  }
}

因此,请您:

assert grailsApplication.config.port.to.somewhere == 8080
assert grailsApplication.config.port.to.another.place == 7070
assert grailsApplication.config.host.to.somewhere == "http://localhost/"
assert grailsApplication.config.host.to.another.place == "https://another.place.com/"




相关问题
Possible to sandbox Python configuration file?

I m thinking of implementing a configuration file written in Python syntax, not unlike what Django does. While I ve seen one or two SO questions about the merits of using executable code in ...

How to validate Java logging properties files?

I have a basic facility for allowing users to remotely apply changes to the logging files in my application. Some logs are configured using java.util.logging properties files, and some are configured ...

Where should I put this configuration setting?

I m designing a fairly small web application which will run on a Sun application server (v9.1). It only has a few pages, no database of its own, and will retrieve/update data via web services. There s ...

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

Dependency bundle (jar-files/sources/API docs) in Eclipse

I m developing various in-house extensions for JIRA, the issue tracker we use. So far I worked with Netbeans and everything worked like a charm. However, now I need to switch to Eclipse and I m ...

热门标签