javax.naming.NameNotFoundException: Unable to resolve 'MyDB'. Resolved '' Weblogic 12.1.3. c

走远了吗. 提交于 2019-11-30 08:23:45

问题


While migrating from Tomcat to Weblogic 12.1.3 I got this exception javax.naming.namenotfoundexception while trying to look up then I have tried the following : NameNotFoundException: While trying to lookup 'jdbc' only when publishing from Eclipse Kepler but not Indigo and How to access JNDI data source defined in weblogic 10.3.6

I got the in titled error now

My lookup code

ds = (DataSource) initContext.lookup("MyDB");

in weblogic JNDI Name

MyDB

Any help please?


回答1:


Unlike Tomcat, weblogic creates multiple servers (Usually an Admin Server, plus at least one other). Each server has to be allocated the data source. In a clustered environment, you need to apply the datasource to the cluster servers.

  1. Log into the Weblogic console, and check the datasource JNDI name (don't confuse this with the datasource name, which is purely to keep the console listing looking pretty). The JNDI name should be something like jdbc/MyDB
  2. Check the datasource Targets tab, and make sure it is applied to the server/cluster you are going to deploy your web app to.
  3. Restart Weblogic. I find that data sources sometimes need this before they become visible to application code.
  4. Deploy your web app to the correct server/cluster.

You should be to connect to the datasource as normal. I always use a Spring JNDI bean, so I can't help with the exact syntax. The suggestions by @Maas look good.




回答2:


Restarting the server after deployment helps.




回答3:


Check the JNDI case (MyDB != MyDb). It sounds trivial, but it happened to me and had a hard time spotting it. Since this is the first thread google returns when searching for this issue, I post it here in case it helps.

Besides that, @kiwiron 's answer covers everything else.




回答4:


For me, starting the managed server from Windows command line instead of starting it using the WebLogic Admin console solved the javax.naming.NameNotFoundException problem. Not sure why this was the case though.



来源:https://stackoverflow.com/questions/25258461/javax-naming-namenotfoundexception-unable-to-resolve-mydb-resolved-weblog

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