问题现象
javax.naming.NameNotFoundException: Unable to resolve 'datasource1'. Resolved ''; remaining name 'datasource1'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1292)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:354)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:227)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:532)
at weblogic.jndi.internal.RootNamingNode.lookup(RootNamingNode.java:84)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:307)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:435)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at TastyList.doGet(TastyList.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:295)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:353)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:250)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3793)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3763)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2451)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2299)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1720)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1680)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:655)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
错误原因及解决方法
1. 认代码中使用的JNDI名和weblogic 中配置的名字不一致
2. 数据源发布的server和web app发布的server不一致
3. 数据源没有成功发布
确认方法1: 在Server的Services->JDBC中,确认是否有使用的JNDI name。不存在的场合,可能是没有发布成功。
确认方法2: 对数据源进行测试
weblogic console中,Services->Data Sources->Monitoring->选择对应数据源->Testing中,选择server,点击【Test Data Source】
解决办法:
- 首先确保数据源中配置的数据已经正常启动
Oracle:
sqlplus username/password as sysdba
连接数据库后,执行 startup ,启动数据实例
断开数据库连接,执行【lsnrctl status】命令,查看实力监听状态
没有监听的场合,会提示没有监听程序。
执行【lsnrctl start】命令启动监听
- 重新发布数据源
手动:
Server的 Data Sources中选择对应数据源,不做任何变更,点击保存,就会重新发布数据源。
自动:
对应数据源->Configuration->Connection Pool->Advanced中, 设置连接重建间隔【Connection Creation Retry Frequency】,数据连接不可用的场合,会间隔指定秒数后,再次尝试创建连接。为0的场合,自动重建连接无效。