亲自试验有2中办法
1.在项目config.groovy添加需要加载的配置文件,如开发环境下配置
development {
runningMode = 'DEV'
grails.logging.jul.usebridge = true
grails.config.locations = ["classpath:datasource_dev.properties"]
}
datasource_dev.properties文件如下填写:
dataSource.url = jdbc:mysql://172.20.0.xx:xxxx/kmrcs
dataSource.username = xxxx
dataSource.password = xxxx
添加后项目启动会优先读取配置文件的连接,项目正常启动.
不过本人遇到有个项目不能读到配置文件,搞了好久才找到答案,
2. 把grails.config.locations = ["classpath:datasource_dev.properties"]放到
DataSource.groovy最前面,这样就能读到了,因为项目正在启动中某种原因导致配置文件还没有被加载.