To describe JNDI, for example, when obtaining a data source, the JNDI address can be written in either of the following ways:
A: Java: COMP/ENV/jdbc/testds
B: JDBC/testds
The configuration methods are also different. The first method is a method that facilitates program transplantation or migration. Its implementation is the same as the concept of "ing, method B is a hard reference.
Java: COMP/ENV is the environment naming context (Environment naming context (ENC), which was introduced after EJB specification 1.1, this is introduced to solve conflicts caused by the original JNDI lookup, and to improve the portability of EJB or J2EE applications.
Commonly used references in J2EE include:
The JDBC data source is referenced in the Java: COMP/ENV/jdbc subcontext.
The JMS connection factory is declared in the Java: COMP/ENV/JMS subcontext
Javamail connection factory declares in the Java: COMP/ENV/mail subcontext
The URL Connection factory is declared in the Java: COMP/ENV/URL subcontext.
The following structure diagram shows the differences between the two descriptions:
A: Java: COMP/ENV/jdbc/testds (Virtual Address) ------> ing descriptor ------> JDBC/testds (actual address)
B: JDBC/testds (actual address)
From this structure, A is indeed easy to transplant.
Let's look at an example:
Assume that you need to obtain datasource, for example, datasource = (datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/testds ");
When you map resources in the configuration file, in Web. XML,
<Resource-ref>
<Res-ref-Name> JDBC/testds </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
In the corresponding resource configuration XML (different application servers are different, and you can perform visual settings in wsad ),
<Reference-Descriptor>
<Resource-description>
<Res-ref-Name> JDBC/dbpool </RES-ref-Name>
<JNDI-Name> oradatasource </JNDI-Name>
</Resource-description>
</Reference-Descriptor>
The actual server's JNDI name is oradatasource, and the logical name JDBC/dbpool is only used to map to it. The advantage of doing so is to improve portability, during migration, you only need to change the configuration file, but the application does not need to be changed.
If you write a general application and want to directly obtain the data source through JNDI, you can directly Lookup ("mytest") (if the JNDI on the server is mytest ), if you use the first method, an error is returned.