Problem with Grails 'war' command which is trying to read the config file
I store the configuration for my Grails application (such as DB configuration) in an XML config file. My DataSource.groovy
is using the config file to get the Database information.
Unfortunately, when I'm building the War file for my test environment (using command such as grails test war stb09.war
), it is running my DataSource.groovy
开发者_如何学C, trying to open the file which is not there in my development environment.
How can I postpone the opening of the file only when I deploy the war file, not in the war building process?
Thank you, Robert
I am supposing you do something like this in your DataSource.groovy
file:
def db = new groovy.util.XmlParser().parse("connection.xml")
Easy and dirty workaround, is to put a try catch around it like this:
try {
def db = new groovy.util.XmlParser().parse("connection.xml")
} catch (Exception e ) {println "Bad timing"}
In my projects, I am actually using something like this:
environments {
production {
grails.config.locations << "classpath:${appName}-db-custom.properties"
}}
This way, no problem at packaging time, and at run time you can replace your datasource with approriate values.
Time-wise, grails is loading the connection data from a compiled DataResource.groovy
first, and then put those in the global configuration. Those values are then dynamically overwritten at run-time by the configuration in the property file.
精彩评论