如何外部化Grails数据配置

编程入门 行业动态 更新时间:2024-10-14 16:24:11
本文介绍了如何外部化Grails数据配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究一个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数据配置

本文发布于:2023-11-25 20:41:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Grails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!