Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a JNDI DataSource without the java:comp/env prefix

I've noticed that both ways of looking up a DataSource using JNDI work:

  1. jdbc/DataSource
  2. java:comp/env/jdbc/DataSource

With the added bonus that the first one doesn't seem to anger Websphere when used from an unmanaged thread ( started by Quartz ).

Are there any pitfalls from accessing JNDI objects without the prefix?

like image 279
Robert Munteanu Avatar asked Aug 10 '10 07:08

Robert Munteanu


People also ask

What is Java comp env in JNDI?

java:comp/env is the node in the JNDI tree where you can find properties for the current Java EE component (a webapp, or an EJB). Context envContext = (Context)initContext.lookup("java:comp/env");

How can I get JNDI DataSource in spring boot?

In the property file you have all properties declared with a prefix – spring. datasource . Therefore using Spring Boot it is very easy to load properties in Java class attributes. Simply specify the prefix using @ConfigurationProperties annotation and add the same property names as class attributes.

What is JNDI in Java with examples?

2. JNDI Description. Any work with JNDI requires an understanding of the underlying service as well as an accessible implementation. For example, a database connection service calls for specific properties and exception handling. However, JNDI's abstraction decouples the connection configuration from the application.


1 Answers

This should be OK, since java:comp/env is the global JNDI namespace. It may depend on the application server where such configurations also appear in the JNDI tree.

Locate your JDBC DataSource in WebSphere Application Server using JNDI

like image 97
stacker Avatar answered Sep 27 '22 21:09

stacker