Adding datasource programmatically to JNDI context in embedded tomcat 7

萝らか妹 提交于 2019-12-05 18:16:21

Oh well i figured it out! Instead of adding it in the GlobalNamingResources

tomcat.getServer().getGlobalNamingResources().addResource(resource);

I added it in the NamingResources

Context rootCtx = tomcat.addContext("", base.getAbsolutePath());
//...
rootCtx.getNamingResources().addResource(resource);

and it works!

If someone can tell me the difference between globalNamingResources and (local)NamingResources and how to lookup a globalNamingResource then please leave me a comment!

Marcel Stör

You don't show us how you look up the JNDI resource. However, in any case the full JNDI name to your resource is java:comp/env/jdbc/db i.e. that's what you need for lookup.

There's further reading here: https://stackoverflow.com/a/4099163/131929

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!