dbrin
dbrin

Reputation: 15673

How to specify portable jndi datsource lookup in grails

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?

Upvotes: 0

Views: 824

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122414

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"
}

Upvotes: 1

Related Questions