gpt4 book ai didi

java - 服务器找不到 java :comp/env/jdbc/my_db data source . .. 在上下文 "java:"中找不到名称 comp/env/jdbc

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:18 25 4
gpt4 key购买 nike

我有一个包含许多模块的 Java EE 应用程序。我正在尝试能够进行间接 JNDI 查找。

我按照以下步骤操作:

ejb-jar.xml: 在每个模块中。我定义了一个企业bean。模块中的所有DAO都继承自这个DAO(MyDataAccessObject)

<小时/>
<enterprise-beans>
<session>
<ejb-name>DataAccessObject</ejb-name>
<ejb-class>com.mycompany.dao.MyDataAccessObject</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref id="MyRef">
<description />
<res-ref-name>jdbc/My_db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
</enterprise-beans>

persistence.xml :我在每个 persistence.xml 中定义(在每个模块中)

<小时/>
<jta-data-source>java:comp/env/jdbc/My_db</jta-data-source>

ibm-application-bnd.xml

<小时/>
 <resRefBindings xmi:id="MyRef" jndiName="jdbc/My_db">

?????? Should I use resRefBindings. If yes, how?
</resRefBindings>

我应该在这个文档中添加什么内容来让 Websphere 了解 java:comp/env/jdbc/My_db?

我已经做的事情是否足够/正确?

目前,如果我想启动应用程序,我会收到此错误:

The server cannot locate the java:comp/env/jdbc/my_db data source for the My_Modul persistence unit because it has encountered the following exception:
Name comp/env/jdbc not found in context "java:".
<小时/>

编辑:我还在事件文件中发现了此错误:

Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1384519 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)

最佳答案

您使用 XMI 绑定(bind) (resRefBindings),该绑定(bind)在 WAS 7.0 中受支持,但被认为已过时。建议使用 XML 绑定(bind)。在 META-INF 中应该有一个名为 ibm-ejb-jar-bnd.xml 的文件,其内容如下:

<ejb-jar-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd" version="1.0">
<session name="DataAccessObject">
<resource-ref name="**datasource_ref_in_your_EJB**" binding-name="jdbc/My_db"/>
</session>
</ejb-jar-bnd>

我还假设您已经在 WAS 中配置了 JNDI 名称“jdbc/My_db”的数据源。

关于java - 服务器找不到 java :comp/env/jdbc/my_db data source . .. 在上下文 "java:"中找不到名称 comp/env/jdbc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18013544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com