I have a servicebuilder portlet that is configured via JNDI:
<Context antiJARLocking="true" useHttpOnly="true">
<ResourceLink name="app/url" global="my-app/app/url"
type="java.lang.String" />
</Context>
In my ext-spring.xml, I try to pull that value using:
<jee:jndi-lookup jndi-name="java:comp/env/app/url" />
However, the InitialContextthat is used to look this value up, seems to be the InitialContext of the ROOT webapp (liferay itself) as the only thing it contains is the java:comp/env/jdbc/LiferayPool database connection pool. I know JNDI contexts are tied to the the ClassLoader determined by:
Thread.currentThread().getContextClassLoader();
And I know liferay mucks with the classloader before running the portlet initialization. But I cannot, for the life of me, figure out how to get around this. Any suggestions?
I have a working solution for you but it is a little bit different of what you've described in your post.
First of all, I propose you to move the declaration of JNDI to server.xml of Tomcat, specifically to < GlobalNamingResources > tag.
Here is an example:
After that you should make a ResourceLink in context.xml:
This will help you to deal with concurrent access if ever you'll have two portlets accessing the same database.
And, finally, ext-spring.xml:
Notice the jdbc/customDBPool
Please note the jdbc/customDBPool which is described in context.xml and which is available not only for ROOT classloader.
In the end you should reference the proper dataSource in your service.xml of LiferayServiceBuilder like that: