...
What can be bound and general overview
There are 3 4 types of objects that can be bound into Jetty's JNDI:
- an ordinary POJO instance
- a java.naming.Reference instance
- an object instance that implements the java.naming.Referenceable interface
- a linkage between a name as referenced in web.xml and as referenced in the environment
The binding for all of these object types generally follows the same pattern:
...
"org.mortbay.jetty.plus.naming.EnvEntry"for <env-entry>s"org.mortbay.naming.plus.Resource"for all other type of resources"org.mortbay.plus.naming.Transaction"for a JTA manager. We'll take a closer look at this in the Configuring XA Transactions section)."org.mortbay.plus.naming.Link"for link between a web.xml resource name and a NamingEntry. See Configuring Links for more info.
There are 3 places in which you can define naming entries:
...
See also the instructions for how to configure JOTM. Contributions of instructions for other transaction managers are welcome.
Configuring Links
| Anchor | ||
|---|---|---|
|
Usually, the name you configure for your NamingEntry should be the same as the name you refer to it as in you web.xml. For example:
| Code Block | ||
|---|---|---|
| ||
In a context xml file:
<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="myds" class="org.mortbay.jetty.plus.naming.Resource">
<Arg><Ref id="wac"/></Arg>
<Arg>jdbc/mydatasource</Arg>
<Arg>
<New class="org.apache.derby.jdbc.EmbeddedDataSource">
<Set name="DatabaseName">test</Set>
<Set name="createDatabase">create</Set>
</New>
</Arg>
</New>
</Configure>
and in web.xml:
<resource-ref>
<res-ref-name>jdbc/mydatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<injection-target>
<injection-target-class>com.acme.JNDITest</injection-target-class>
<injection-target-name>myDatasource</injection-target-name>
</injection-target>
</resource-ref>
|
If you wish, you can refer to it in web.xml by a different name, and link it to the name in your org.mortbay.jetty.plus.naming.Resource by using an org.mortbay.jetty.plus.naming.Link type of NamingEntry. For the example above, we could refer to the jdbc/mydatasource resource as {{jdbc/mydatasource1}
by doing:
| Code Block | ||
|---|---|---|
| ||
In a context xml file:
<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="myds" class="org.mortbay.jetty.plus.naming.Resource">
<Arg><Ref id="wac"/></Arg>
<Arg>jdbc/mydatasource</Arg>
<Arg>
<New class="org.apache.derby.jdbc.EmbeddedDataSource">
<Set name="DatabaseName">test</Set>
<Set name="createDatabase">create</Set>
</New>
</Arg>
</New>
</Configure>
in a jetty-env.xml file:
<New id="map1" class="org.mortbay.jetty.plus.naming.Link">
<Arg><Ref id='wac'/></Arg>
<Arg>jdbc/mydatasource1</Arg> <!-- name in web.xml -->
<Arg>jdbc/mydatasource</Arg> <!-- name in container environment -->
</New>
and in web.xml:
<resource-ref>
<res-ref-name>jdbc/mydatasource1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<injection-target>
<injection-target-class>com.acme.JNDITest</injection-target-class>
<injection-target-name>myDatasource</injection-target-name>
</injection-target>
</resource-ref>
|
This can be useful when you cannot change web.xml but need to link it to a resource in your deployment environment.
Global or scoped to a webapp
...