我正在研究一个Grails项目,该项目需要在WAR文件部署到服务器后才能更改它的数据源。我怎样才能做到这一点?我尝试了这里列出的方法 https:// translate ?.google /翻译SL =汽车&安培; TL = EN&安培; JS = Y&安培;一个先前= _t&安培; HL = EN&安培,即= UTF-8和; U = HTTP%3A%2F%2Flaurobecker.wordpress%2F2011%2F03 %2F25%2Fdatasource-arquivo-properties%2F& edit-text =& act = url 以及外部化Grails数据源配置,但他们似乎并没有为我工作。有人可以向我解释整个过程,我的选择是什么?如果我的问题不是非常技术性的,我以前从未这么做过,所以原谅我。谢谢!
解决方案据我所知,有两个选项可用。第一个是,如这里所述,并在官方文档,您可以将config.groovy分割为不同的文件。所以你也可以包含类路径中的文件,当前用户的主目录等等。文档中的例子是: $ p $ grails.config.locations = [classpath:$ {appName} - config.properties,classpath:$ {appName} -config.groovy,file:$ {userHome} /。grails / $ {appName} -config.properties,file:$ {userHome} /。grails / $ {appName} -config.groovy
另一种方法是,您可以在应用程序服务器中设置JNDI参数,并在config.groovy中使用它,如 dataSource { jndiName =java:comp / env / myDataSource}
I am working on a Grails project that needs to be able to change it's data source once the WAR file is deployed to a server. How can I do this? I have tried the method listed here translate.google/translate?sl=auto&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Flaurobecker.wordpress%2F2011%2F03%2F25%2Fdatasource-arquivo-properties%2F&edit-text=&act=url as well as here Externalizing Grails Datasource configuration but they do not seem to be working for me. Can someone explain this entire process to me, and what my options are? I have never done this before so forgive me if my question isnt very technical. Thanks!
解决方案As i know, there are two options available. the first one is, as described here and in the official docs, that you can split your config.groovy in different files. So you can also include files from the classpath, the home directory of the current user and so on. The example from the docs is:
grails.config.locations = [ "classpath:${appName}-config.properties", "classpath:${appName}-config.groovy", "file:${userHome}/.grails/${appName}-config.properties", "file:${userHome}/.grails/${appName}-config.groovy" ]The other approach is, that you can set a JNDI Parameter in the app server and use this in your config.groovy as described here in the offical docs:
dataSource { jndiName = "java:comp/env/myDataSource" }
更多推荐
如何外部化Grails数据配置
发布评论