问题
I'm trying to run an existing WebSphere application in Liberty Profile but have run into a problem. The application has a resource environment entry configured in the server which I need to translate into a Liberty Profile resource. How can I configure a JNDI resource in the server.xml, that isn't a datasource (dataSource) or a constant (jndiEntry)?
Many thanks
回答1:
You can configure this using the element in the server.xml. This is documented in the infocenter. Essentially you enable the jndi feature in the server.xml using this:
<featureManager>
<feature>jndi-1.0</feature>
</featureManager>
Then you can configure the JNDI entries. You can only do simple types using this, so no complex objects. To configure your entry you then do this:
<jndiEntry jndiName="myProp/philosopher" value="plato" />
The Liberty profile does type inference, so if you expressed this:
<jndiEntry jndiName="myProp/philosopher" value="1234" />
you get an Number from JNDI. If you express this:
<jndiEntry jndiName="myProp/philosopher" value="1234.3D" />
You get a Double.
If you want a number as a string literal you would express it using quotes:
<jndiEntry jndiName="myProp/philosopher" value='"1234.3D"' />
To get this from your application you can do a global lookup such as:
Context ctx = new InitialContext();
Object jndiConstant = ctx.lookup("myProp/philosopher");
String philosopher = (String) jndiConstant;
You can also map this to a resource environment entry in the ibm-web-bnd.xml file:
<env-entry name="philosopher" binding-name="myProp/philosopher" />
and then use this code to look it up:
Context ctx = new InitialContext();
Object jndiConstant = ctx.lookup("java:comp/env/philosopher");
String philosopher = (String) jndiConstant;
回答2:
Currently this is not possible with Liberty Profile. This question was answered in the IBM WasDev forum here https://developer.ibm.com/answers/questions/6221/resource-environment-entries-in-liberty-profile/?community=wasdev A RFE process (31525) has been created for it to support it in a future release.
回答3:
In 8.5.5.x there are several new entries:
For example: To configure an URL you can use the jndiURLEntry
来源:https://stackoverflow.com/questions/18083341/configuring-a-jndi-resource-that-isnt-a-datasource-in-liberty-profile