论坛首页 Java企业应用论坛

Websphere6.1部署项目时报错,连接不上jndi Name not found in context "java:"

浏览 5237 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-09-13  
最近在websphere 上部署一个项目时,总是报下面的错误,在tomcat上是好的。websphere上我已经配置好jndi 测试连接也是通过的。网上查了很多资料,还是没有好的解决办法。我用的是spring ,数据源是这样配置的
<bean id="baseDaoEntity" class="com.para.osc.framework.common.base.BaseDaoEntity" init-method="initEntity">
<property name="dataSource" ref="dataSource" />
<property name="dataBaseType">
<value>MYSQL</value>
</property>
<property name="jndiName">
<value>jdbc/oscdb</value>
</property>
</bean>

javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the serverruntime is not able to associate the operation's thread with any J2EE application component. This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request. Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names. [Root exception is javax.naming.NameNotFoundException: Name not found in context "java:".]

小弟是初次在websphere上部署项目
   发表时间:2012-09-13  
websphere 使用JNDI要在ibm-web-bnd.xml和web.xml文件里配置。否则会报找不到相应名字数据源的错误。
建议使用IBM Rational Application Developer进行开发。
0 请登录后投票
   发表时间:2012-09-13  
给你个例子:
ibm-web-bnd.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd 
	xmlns="http://websphere.ibm.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
	version="1.0">

	<virtual-host name="default_host" />
	
	<!-- Binding for Data Source,  -->
	<resource-ref name="jdbc/oscdb" binding-name="jdbc/oscdb"></resource-ref>
	
</web-bnd>

web.xml:
<!-- Data Source Reference -->
<resource-ref>
	<res-ref-name>jdbc/oscdb</res-ref-name>
	<res-type>javax.sql.XADatasource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
0 请登录后投票
   发表时间:2012-09-13  
其中ibm-web-bnd.xml和web.xml在同一目录WEB-INF下
0 请登录后投票
   发表时间:2012-09-13  
WS6 你部暑应用时候,注意下几点:

1: java:comp/env/jdbc/bbt 是全称形式,

2: jdbc/bbt 这是一个简写形式,

你如果向WS6部暑时候,好像我没有记错的话有一个让容器管理(数据源),就用简写形式了,你两形式切换下!
0 请登录后投票
   发表时间:2012-09-14  
was连接 JDNI数据源要使用;
initContext = new InitialContext();
Context envCtx = (Context) initContext.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup(jndiName);
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics