Reputation: 94
I have deployed an spring boot web application in WAS Liberty server (WebSphere Application Server Version 8.5.5.9 Liberty Profile).
I have a JNDI url entry added in server.xml which is given below but one of my class in api is not able to access it.
<jndiURLEntry jndiName="url/SSOService" value="http://ssoserver.dev.intranet/SSOService/SSOFacade" />
I found one weird thing in Liberty is that whenever I add java:comp/env/ to any of the JNDI entry , application is not able to pick it and getting javax.naming.NameNotFoundException:
I fixed the datasource issue by not adding the prefix, but the above URL is used in only of the api which is not in my control.
So how can we enable java:com/env prefix in Websphere Liberty server ? or is there any alternative available to make this working ?
Upvotes: 1
Views: 1830
Reputation: 42926
When you define a JNDI URL entry in the following way:
<jndiURLEntry jndiName="url/SSOService" value="..."/>
It will make the java.net.URL
available literally at the url/SSOService
name (i.e. no sort of java:
prefix). Looking up a JNDI entry from this location is known as a "direct lookup", because you are looking something up that was defined directly in server configuration.
If you want to register this in the java:comp/env/
namespace, you must define a "resource reference", which will create a binding from the server-defined entry to a java:comp/env/
entry. A resource reference can be defined annotatively or via web.xml.
Here is how you can define an annotative resource reference:
@Resource(lookup="url/SSOService", name="url/SSOServiceRef")
URL ssoServiceURL;
In this example, we're saying:
url/SSOService
java:comp/env/url/SSOServiceRef
Upvotes: 1