四日前、私はこのエラーメッセージ私は私のDBに接続しようとするたびに入門:java.lang.NoClassDefFoundErrorが:javaxの/永続化/ SPI /はPersistenceProvider
java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider
私はいくつかの後にそれを得ました私のアプリの他の部分で作業していた時間、DBアクセスを含まないので、私は本当にこのエラーの原因を知りません。 私が過去4日間に行ったことは、上記のエラーのさまざまな組み合わせをグーグルで試してみることでした... グーグルで行った後、エラーが発生しましたが、そうではありません。 (javax.persistence.jar
とjavax.persistence-2.1.0-rc1.jar
が私のWebContent/WEB-INF/lib
にあり、Web App Libraries
がビルドパスに含まれています)。 私が考えた唯一の他のものは、おそらく私はいくつかのバージョンの矛盾があり、それが理由でjavax.persistence.spi.PersistenceProvider
をビルドすることはできませんが、私はそれをチェックする手掛かりがありません。 そして、私は間違って、別の問題があるということだ可能性もあります....
私はここに私の/WebContent/WEB-INF/web.xml
と/src/main/resources/META-INF/persistence.xml
を追加しています。必要なものがあればお知らせください。追加します。 私はすでにこの問題を4日間解決しようとしてきました。私は本当に失望しています。助けてください!
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<display-name>InaalEchtok</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
persistence.xml
:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="model_persistence_unit">
<description>Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- <class></class> -->
<properties>
<!-- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/fdb" /> -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/fdb?createDatabaseIfNotExist=true" />
<property name="javax.persistence.jdbc.user" value="****" />
<property name="javax.persistence.jdbc.password" value="*********" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
</properties>
</persistence-unit>
</persistence>
これらは私の参照されるライブラリです:
と、これは私のWEB-INF/lib
です:
なぜ2つのバージョンのjavax.persistence jarがあるのですか?削除してみてください。 – ProgrammersBlock
1つのバージョンを削除できない場合は、クラスを初期化できないときにこのエラーが発生し、その後はNoClassDefFoundErrorになります。初期化を解決して成功させることができれば、エラーも解決されます。 –
@ProgrammersBlockあなたは 'javax.persistence.jar'と' javax.persistence-2.1.0-rc1.jar'を意味しますか? –