javax.naming.NameNotFoundException: Unable to resolve 'jdbc.mydb'. Resolved 'jdbc'; remaining name '

WebLogic中JNDI遇到的非常非常小的问题:

错误如下:

javax.naming.NameNotFoundException: Unable to resolve 'jdbc.mydb'. Resolved 'jdbc'; remaining name 'mydb'
	at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1180)
	at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:270)
	at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:187)
	at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:210)
	at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:224)
	at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:253)
	at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:426)
	at javax.naming.InitialContext.lookup(InitialContext.java:411)
	at jsp_servlet.__index._jspService(__index.java:101)
	at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
	at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
	at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
	at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
	at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
	at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
	at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
	at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)


代码连接如下:

DataSource ds = (DataSource)ctx.lookup(“jdbc.mydb”);



出现这个是由于没有找到JNDI,(其实是废话,报错已经说明了 ^_^);

解决方法:

在Weblogic数据源管理中的

JDBC Data Source-0的设置

中设置目标选项

将服务勾选上,如默认的:AdminServer
保存后即可;



`javax.naming.NoInitialContextException`是一个异常类,它属于Java的命名和目录服务(JNDI)API的一部分。当尝试访问命名服务,但是没有正确地配置初始上下文环境时,就可能抛出这个异常。具体来说,这个异常提示需要在环境变量或系统属性中指定类名。 这个异常通常发生在以下情况: 1. 在使用JNDI之前,没有配置初始上下文环境(InitialContext),即没有指定JNDI提供者、环境属性、工厂类等。 2. 程序中缺少必要的JNDI服务实现库,或者在系统属性中没有正确指定JNDI服务的类名。 要解决这个异常,你需要检查代码中与JNDI相关的配置部分,确保提供了所有必要的环境属性,例如: - `java.naming.factory.initial`:指定JNDI提供者初始化时使用的工厂类的类名。 - `java.naming.provider.url`:指定JNDI服务提供者的位置。 - 其他环境属性,如认证信息等。 例如,如果你在Java代码中使用JNDI查找对象,你可能需要先创建一个`InitialContext`对象,并且提供必要的环境参数。 ```java Properties props = new Properties(); props.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory"); props.put("java.naming.provider.url", "iiop://localhost:1050"); InitialContext ctx = new InitialContext(props); ``` 在这个例子中,`props`对象被用来设置初始化环境,指定了工厂类和JNDI服务的位置。然后,使用这些属性创建了一个`InitialContext`实例。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值