服务器无法找到java:comp / env / jdbc / my_db数据源...在上下文中找不到名称comp / env / jdbc“java:”

时间:2013-08-02 09:36:12

标签: 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-应用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)

1 个答案:

答案 0 :(得分:1)

您使用WAS 7.0中支持但过时的XMI绑定(resRefBindings)。建议使用XML绑定。在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”的数据源。