【问题标题】:Could not find any META-INF/persistence.xml file in the classpath on WebProject在 WebProject 的类路径中找不到任何 META-INF/persistence.xml 文件
【发布时间】:2016-06-24 20:56:05
【问题描述】:

在彻底搜索这个论坛寻找答案后,我找不到一个与我相似的案例。

使用 maven 生成 WAR 文件管理器并部署我的服务器后,每次我向需要创建 DAO 的 API 发送 GET 请求时,我都会在服务器控制台上收到以下警告:

在类路径中找不到任何 META-INF/persistence.xml 文件

还有以下例外:

没有名为 mim_ajuda 的 EntityManager 的持久性提供程序

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">


<persistence-unit name="mim_ajuda" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  <exclude-unlisted-classes>false</exclude-unlisted-classes>
  <properties>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/mim_ajuda" />
    <property name="javax.persistence.jdbc.user" value="root" />
    <property name="javax.persistence.jdbc.password" value="B@ck3nd" />
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
    <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.format_sql" value="true" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    <property name="hibernate.hbm2ddl.auto" value="validate" />
    <!-- Configuring Connection Pool -->
    <property name="hibernate.c3p0.min_size" value="5" />
    <property name="hibernate.c3p0.max_size" value="20" />
    <property name="hibernate.c3p0.timeout" value="500" />
    <property name="hibernate.c3p0.max_statements" value="50" />
    <property name="hibernate.c3p0.idle_test_period" value="2000" />
    </properties>
  </persistence-unit>
</persistence>'

关于这部分代码:

private EntityManager getEntityManager(){ EntityManagerFactory factory = Persistence .createEntityManagerFactory("mim_ajuda"); if(entityManager == null){ entityManager = factory.createEntityManager(); }
return entityManager; }

在我进一步讨论之前,我已经搜索了放置 persistence.xml 的位置,并且根据THIS 页面和其他几个用户,XML 必须在“WEB-INF/classes/META-战争文件中的 INF/persistence.xml" 目录(我的是):

WAR directory Image

总结一下:

  1. 自动化测试工作正常,离线运行并使用 entityManager
  2. 只有当我调用 web 服务 API 时才会收到此错误
  3. persinstence.xml 文件遵循其他问题中显示的路径。

【问题讨论】:

    标签: xml maven tomcat web persistence.xml


    【解决方案1】:

    找到了解决办法。解析器区分大小写,因此我找不到我的 Persistance.xml。重命名为persistance.xml就可以了

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 2014-09-22
      相关资源
      最近更新 更多