1

j2e アプリケーションでこの問題が発生しましたが、解決策が見つかりません。ビルドは成功しましたが、実行時例外がスローされました。Google からの多くのアドバイスを試しましたが、何も問題を解決できません。

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/datasource-config.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot parse persistence unit from class path resource [META-INF/persistence.xml]

データ ソースの entityManagerFactory

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" >
    <property name="connectionCachingEnabled" value="true" />
    <property name="URL" value="jdbc:postgresql://localhost:5432/postgres" />
    <property name="user" value="postgres" />
    <property name="password" value="" />
</bean>


<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
        </bean>
    </property>
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="default" />

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="dataSource" ref="dataSource" />
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean
    class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

persistence.xml

 <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">

            <class>com.example.j2eeapp.domain.UserEntity</class>

    </persistence-unit>
4

3 に答える 3

0

私は同様の問題を抱えていましたが、私のxmlファイルにはpersistence.xmlへの正しいパスがありました。問題は、エンティティ間の関係が間違っていたことです。また、日付のインポートが間違っていました(sql.Dateを使用しないSpring Data JPAを使用しました)

于 2015-01-10T11:15:42.893 に答える
0

1)データソースクラスを確認してくださいoracle.jdbc.pool.OracleDataSource

2)データベースの詳細を確認します-ユーザー名、パスワード、ドライバーURL

上記の詳細が正しい場合。

3) バックエンドにデータベースを作成し、参照してみる。また、コードが参照しているすべてのテーブルとエンティティが存在することを確認してください。

4)Tomcat(Webサーバー)をきれいにして、アプリケーションを再起動してみてください

同じ問題がありました。上記の手順で解決しました。お役に立てれば !!!

于 2016-11-28T10:32:43.480 に答える