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

标签 java deployment websphere datasource java-ee-6

我有一个包含许多模块的 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/

相关文章:

java - 将模型传递给包含的 JSP?

ruby - 是否有基于 Rack 或 Sinatra 的环境配置实用程序?

java - 无法在 Websphere 上使用 PostgreSQL 配置 EJB 计时器

java - 在 websphere 应用服务器中通过 spring 加载资源

jsp - websphere上的jSTL el函数错误

java - 基于 AspectJ 带注释的切入点未被调用

java - 使用多个 AnntationProcessor 找不到 FluentFuture 类

java - 如何从 Android 上传文件到 Node.js 服务器

java - 与 EAR 包装相比,WAR 包装有什么缺点吗?

deployment - Grails部署错误