问题
My problem is that I've put a well-formed properties file in my classpath and told grails to look for the properties file in my classpath, but the properties in the file aren't overriding the existing ones.
In my config.groovy I have the lines:
grails.config.locations = [ "classpath:${appName}-config.properties",
"file:./${appName}-config.properties"]
// verified that appName is being used. It prints out classpath:XXX-config.properties, as expected, where XXX is my appname.
println "grails.config.locations: ${grails.config.locations}"
In my XXX-config.properties, I specify a different DB connection URL (this is the one I want to use):
dataSource.url=jdbc:postgresql://products.yyyyy.ap-southeast-1.rds.amazonaws.com:5432/mydatabasename
Then I put the XXX-config.properties in my classpath and startup tomcat7, but the errors are thrown, saying it can't find my deliberately fake db, meaning the database property did not get overridden.
Now I'm thinking my classpath is wrong, but I do ps aux | grep tomcat which tells me that the command line arg for tomcat7 contains " -classpath :/home/jbu/:_other_paths_here_". Note I put my properties file at /home/jbu/XXX-config.properties. I am slightly concerned about that leading colon, but it doesn't seem to cause any other problems.
So the classpath dir appears correct, so now I thought maybe my properties file isn't properly formatted, so I added a harded "file:/home/jbu/XXX-config.properties" to my grails.config.locations, and the properties were found and successfully overridden, meaning nothing is wrong with the properties file itself.
I don't have any more ideas here. Can someone help me out?
Sidenote: I modified the CLASSPATH variable for tomcat7 by adding this line to /usr/share/tomcat7/bin/setenv.sh:
export CLASSPATH="${CLASSPATH}:/home/jbu/"
回答1:
This (among with many other things in Grails, it seems) is broken. Sigh...I'm using grails 2.4.5 so I'm a bit surprised that it has been broken since 1.3.5.
http://jay-chandran.blogspot.com/2010/10/grails-using-external-properties-file.html
Grails 1.3.5: How to configure Datasource.groovy to either connect to MySQL or SQL Server
来源:https://stackoverflow.com/questions/42839975/classpath-property-file-in-grails-app-is-not-being-used