How to specify portable jndi datsource lookup in grails

孤街浪徒 提交于 2020-01-17 05:45:20

问题


I know JNDI lookup in grails is as simple as

datasource {
  jndiName = "java:comp/env/myDataSource"
}

this works great on Tomcat.

On other containers (WebLogic, JBOSS, etc.) the jndiName for the same thing would be just myDataSource . The question is how do I configure this to be generic and portable so that the code does not need to be changed based on the deploy target?


回答1:


You might be able to key off a system property that you know will be set when running in Tomcat and not set anywhere else, e.g.

datasource {
  jndiName = "${System.getProperty('catalina.home') ? 'java:comp/env/' : ''}myDataSource"
}


来源:https://stackoverflow.com/questions/13423067/how-to-specify-portable-jndi-datsource-lookup-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!