【问题标题】:Tomcat + Mysql - Unable to find java:compTomcat + Mysql - 无法找到 java:comp
【发布时间】:2014-06-05 22:00:54
【问题描述】:

我正在尝试使用 tomcat + mysql 开发 Web 应用程序,这是我的配置:

persistence.xml

<persistence-unit name="EntityMappings" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <non-jta-data-source>
        java:comp/env/jdbc/EntityMappings
    </non-jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
        <property name="javax.persistence.schema-generation.database.action"
                  value="none" />
    </properties>
</persistence-unit>

web.xml

    <resource-ref>
    <description>MySQL Datasource example</description>
    <res-ref-name>jdbc/EntityMappings</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

context.xml(在tomcat/config下)

<Resource name="jdbc/EntityMappings" auth="Container" type="javax.sql.DataSource"
           maxActive="50" maxIdle="30" maxWait="10000"
           username="XXX" password="XXX" 
           driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:3306/EntityMappings"/>

我的架构是 EntityMappings。

运行后出现一些错误:

Name [java:comp/env/jdbc/EntityMappings] is not bound in this Context. Unable to find [java:comp].

Unable to lookup JNDI name [java:comp/env/jdbc/EntityMappings]

javax.persistence.PersistenceException: Unable to build entity manager factory

我已将 mysql 驱动程序放在我的 tomcat/lib (mysql-connector-java-5.1.30-bin.jar) 下

【问题讨论】:

  • 请同时发布您的 Spring 配置

标签: java mysql spring-mvc servlets tomcat7


【解决方案1】:

尝试从您的 persistence.xml 中删除 java:comp/env 前缀:

<non-jta-data-source>
    jdbc/EntityMappings
</non-jta-data-source>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 2018-06-13
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多