0

JUnit の開始時に blueprint.xml と persistence.xml をロードするテスト ケースがありますが、実際にテストを実行すると、永続化プロバイダーがないためにエラーがスローされます。

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named blacklisting-pu 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:92)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.apache.camel.component.jpa.JpaEndpoint.createEntityManagerFactory(JpaEndpoint.java:255)
at org.apache.camel.component.jpa.JpaEndpoint.getEntityManagerFactory(JpaEndpoint.java:165)
at org.apache.camel.component.jpa.JpaEndpoint.validate(JpaEndpoint.java:248)
at org.apache.camel.component.jpa.JpaEndpoint.createProducer(JpaEndpoint.java:103)
at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:405)

プロバイダーがロードされたことを示すログの最初の部分を次に示します。

16  blacklisting-pu  TRACE  [main] openjpa.Runtime - Setting the following properties from "file:/workspace/git/jdbc-util/target/test-classes/META-INF/persistence.xml" into configuration: {openjpa.jdbc.SynchronizeMappings=buildSchema(SchemaAction='add,deleteTableContents'), openjpa.ConnectionPassword=, openjpa.ConnectionDriverName=org.h2.Driver, javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl, openjpa.MetaDataFactory=jpa(Types=com.entity.MyEntity), openjpa.Log=DefaultLevel=TRACE, Tool=INFO, PersistenceVersion=1.0, openjpa.ConnectionUserName=, openjpa.ConnectionURL=jdbc:h2:mem:blacklisting;DB_CLOSE_DELAY=1000, openjpa.Id=blacklisting-pu}
74  blacklisting-pu  TRACE  [main] openjpa.Runtime - No cache marshaller found for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
119  blacklisting-pu  TRACE  [main] openjpa.Runtime - No cache marshaller found for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
128  blacklisting-pu  TRACE  [main] openjpa.MetaData - Scanning resource "META-INF/orm.xml" for persistent types.
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - The persistent unit root url is "null"
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames() found [com.entity.BlacklistingEntity].
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - Found 1 classes with metadata in 9 milliseconds.
132  blacklisting-pu  TRACE  [main] openjpa.MetaData - Clearing metadata repository"org.apache.openjpa.meta.MetaDataRepository@1766bfd8".

春を使用してテストケースを機能させ、春の camel-context.xml でルートを定義しましたが、ルートを blueprint.xml に移動する必要があり、実行時に persistence.xml が見つからないようです。テスト。
私はこれを多くのグーグルとともに参考として使用してきました: http://camel.apache.org/blueprint-testing.html どんな助けでも大歓迎です

編集: JUnit のセットアップ メソッドの一部として以下を実行しましたが、calss は問題なく見つかりました

Object obj = Class.forName("org.apache.openjpa.persistence.PersistenceProviderImpl").newInstance();
    if(null==obj){
        Assert.fail("org.apache.openjpa.persistence.PersistenceProviderImpl not present on classpath.");
    }else{
        LOG.info("the class {} exists on the calsspath.",obj.getClass().getName());
    }

これがロードされたことを示すログです

Creating service instance
Service created: org.apache.aries.blueprint.ext.impl.ExtNamespaceHandler@10a33ce2
Creating listeners
the class org.apache.openjpa.persistence.PersistenceProviderImpl exists on the calsspath.

Persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="blacklisting-pu" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>com.entity.BlacklistingEntity</class>
    <properties>
        <property name="openjpa.ConnectionURL" value="jdbc:h2:mem:blacklisting;DB_CLOSE_DELAY=1000" />
        <property name="openjpa.ConnectionDriverName" value="org.h2.Driver" />
        <property name="openjpa.ConnectionUserName" value="" />
        <property name="openjpa.ConnectionPassword" value="" />
        <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=INFO" />
        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(SchemaAction='add,deleteTableContents')" />
    </properties>
</persistence-unit>

</persistence>
4

0 に答える 0