Java NameNotFoundException:仅在从 Eclipse Kepler 而非 Indigo 发布时尝试查找“jdbc”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21355945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NameNotFoundException: While trying to lookup 'jdbc' only when publishing from Eclipse Kepler but not Indigo
提问by user3236055
I'm able to publish my web-app to an Oracle Weblogic 12c (12.1.1) AdminServer from Eclipse Indigo 3.7.2 with oepe 12.1.1.1.1
我可以使用 oepe 12.1.1.1.1 从 Eclipse Indigo 3.7.2 将我的网络应用程序发布到 Oracle Weblogic 12c (12.1.1) AdminServer
However, the exact same web-app imported into Eclipse Kepler 4.3.1 with oepe 12.1.2.2 fails to publish with the following (fairly well trodden) exception and I'm trying to work out why?...
但是,使用 oepe 12.1.2.2 导入 Eclipse Kepler 4.3.1 的完全相同的 Web 应用程序无法发布以下(相当不错的)异常,我正在尝试找出原因?...
NameNotFoundException: While trying to lookup 'jdbc.oraclexe' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/oraclexe']; Link Remaining Name: 'jdbc/oraclexe'
NameNotFoundException:尝试查找“jdbc.oraclex”时未找到子上下文“jdbc”。解决 ''; 剩余名称'jdbc/oraclex']; 链接剩余名称:'jdbc/oraclex'
The Weblogic 12c data source is definitely available and I have to assume its configured correctly as the application deploys and runs with no problems when published from Indigo.
Weblogic 12c 数据源绝对可用,我必须假设它的配置正确,因为应用程序在从 Indigo 发布时部署和运行没有问题。
I'm also assuming the mappings in applicationContext.xml, web.xml and weblogic.xml are corrects as again there are no problems when published from Indigo. The mappings are as follows...
我还假设 applicationContext.xml、web.xml 和 weblogic.xml 中的映射是正确的,因为从 Indigo 发布时再次没有问题。映射如下...
src\main\webapp\WEB-INF\spring\applicationContext.xml
src\main\webapp\WEB-INF\spring\applicationContext.xml
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/oraclexe" />
</bean>
src\main\webapp\WEB-INF\web.xml
src\main\webapp\WEB-INF\web.xml
<resource-ref>
<description>Oracle Weblogic Connection Pool (oraclexe)</description>
<res-ref-name>jdbc/oraclexe</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/oraclexe</mapped-name>
</resource-ref>
build\weboutput\WEB-INF\weblogic.xml
构建\weboutput\WEB-INF\weblogic.xml
<resource-description>
<res-ref-name>jdbc/oraclexe</res-ref-name>
<jndi-name>oraclexe</jndi-name>
</resource-description>
I am wondering if the weblogic.xml isn't being made available during deployment (i.e its not being copied to the src\main\webapp\WEB-INF folder) rather than a problem with the mappings between jndiName/resource-ref/res-ref-name themselves? I've tried putting weblogic.xml directly in the src\main\webapp\WEB-INF folder but I get the same exception.
我想知道 weblogic.xml 在部署期间是否不可用(即它没有被复制到 src\main\webapp\WEB-INF 文件夹)而不是 jndiName/resource-ref/res 之间的映射问题-ref-name 自己?我试过将 weblogic.xml 直接放在 src\main\webapp\WEB-INF 文件夹中,但我得到了同样的异常。
My only other thought is that Indigo oepe 12.1.1.1.1 is happy publishing to Weblogic 12.1.1 but Kepler oepe 12.1.2 isn't and I should be publishing to a Weblogic 12.1.2 server?
我唯一的其他想法是 Indigo oepe 12.1.1.1.1 很高兴发布到 Weblogic 12.1.1 但 Kepler oepe 12.1.2 不是,我应该发布到 Weblogic 12.1.2 服务器?
回答by user3236055
After a week or so of trial and error / process of elimination I've managed to resolve this issue and get a better understanding of the necessary mappings. As Elliott suspected this was a problem with the JNDI lookup. It was compounded by the fact that it (inadvertently) works as expected when published from Indigo to weblogic 12.1.1 (I'm still unsure why that's the case).
经过一周左右的反复试验/消除过程,我设法解决了这个问题,并更好地了解了必要的映射。正如 Elliott 怀疑这是 JNDI 查找的问题。当从 Indigo 发布到 weblogic 12.1.1 时,它(无意中)按预期工作(我仍然不确定为什么会这样)使情况更加复杂。
My initial attempts to resolve this had focused on the mappings in the weblogic.xml. As I was publishing to a weblogic server I was in incorrectly assuming this was referenced when resolving the data source. As it turns out this isn't the case and my configuration didn't require a weblogic.xml resource-description.
我最初解决这个问题的尝试集中在 weblogic.xml 中的映射上。当我发布到 weblogic 服务器时,我错误地假设在解析数据源时引用了它。事实证明情况并非如此,我的配置不需要 weblogic.xml 资源描述。
The applicationContext.xmlremains the same...
在applicationContext.xml中保持不变...
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/oraclexe" />
</bean>
However, the jndiName value of java:comp/env/jdbc/oraclexemaps to the web.xml res-ref-name value jdbc/oraclexe(and not the weblogic.xml res-ref-name as I'd wrongly assumed)...
但是, java:comp/env/ jdbc/oracleexe的 jndiName 值映射到 web.xml res-ref-name 值jdbc/oraclex(而不是 weblogic.xml res-ref-name ,因为我错误地假设)。 ..
The web.xmlmapped-name has been amended...
在web.xml中映射的名称已经修改...
<resource-ref>
<description>Oracle Weblogic console JDBC Data Source</description>
<res-ref-name>jdbc/oraclexe</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>oraclexe</mapped-name>
</resource-ref>
...it's then the mapped-name value oraclexethat maps to the Weblogic console JDBC Data Source JNDI name.
...然后映射名称值oraclexe映射到 Weblogic 控制台 JDBC 数据源 JNDI 名称。
The resource-description node in the weblogic.xml has now been completely omitted as its not referenced in this particular configuration.
weblogic.xml 中的资源描述节点现在已完全省略,因为它在此特定配置中未引用。
回答by c3po
In my case, configuration was Weblogic 12.1.3 and Eclipse Mars 4.5.0; the ear worked fine deployed on wls but I had the same error when publishing from elipse. The problem was that the destiny of the datasource was a server created to deploy the application, and the eclipse published it on AdminServer. I added both destinies to the datasource, and it worked ok.
就我而言,配置是 Weblogic 12.1.3 和 Eclipse Mars 4.5.0;耳朵在 wls 上部署得很好,但是从 elipse 发布时我遇到了同样的错误。问题是数据源的命运是为部署应用程序而创建的服务器,Eclipse 将它发布到 AdminServer 上。我将两个命运都添加到数据源中,并且运行正常。
回答by Enrique de Miguel
This is a configuration that worked for me:
这是一个对我有用的配置:
applicationContext.xml
应用上下文.xml
<jee:jndi-lookup id="dataSource" resource-ref="true"
jndi-name="jdbc/alias" expected-type="javax.sql.DataSource" />
web.xml
网页.xml
<resource-ref>
<res-ref-name>jdbc/alias</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
weblogic.xml
weblogic.xml
<wls:resource-description>
<wls:res-ref-name>jdbc/alias</wls:res-ref-name>
<wls:jndi-name>jdbc/resource/weblogic</wls:jndi-name>
</wls:resource-description>