Apache camel 使用openJPA的JUnit测试蓝图正在进行中

Apache camel 使用openJPA的JUnit测试蓝图正在进行中,apache-camel,junit4,openjpa,blueprint,Apache Camel,Junit4,Openjpa,Blueprint,我有一个测试用例,它在JUnit开始时加载blueprint.xml和persistence.xml,但当测试实际运行时,会因为没有持久性提供程序而引发错误 Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named blacklisting-pu at javax.persistence.Persistence.createEntityManagerFac

我有一个测试用例,它在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".
我让测试用例使用spring并在spring camel-context.xml中定义路由,但后来我需要将路由移动到blueprint.xml,现在它似乎无法在运行时为测试找到persistence.xml。
我一直在用这个作为我的参考,还有很多谷歌搜索: 任何帮助都将不胜感激

编辑: 我已经在JUnit中作为安装方法的一部分运行了以下内容,并且发现Cals没有问题

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>

org.apache.openjpa.persistence.PersistenceProviderImpl
com.entity.blacklistingenetity

在类路径中是否有诸如Hibernate或OpenJPA之类的持久性提供程序?是的,我在类路径上有OpenJPA,并且我正在使用OpenJPA java代理运行测试用例。就像我说的,我有两个相同的上下文,一个是spring驱动的,另一个是in和OSGI蓝图。spring驱动的版本运行得很好,但另一个版本不行。您在
persistence.xml
中添加了
org.apache.openjpa.persistence.persistence.PersistenceProviderImpl
?我修改了我的帖子,以显示我当前的persistence.xml,其中包含了提供程序。控制台日志还显示从persistence.xml文件加载的属性。它最初附加在上面堆栈跟踪的正下方。您是否使用驼峰测试蓝图进行单元测试?它不是一个完整的OSGi容器,所以不是所有的事情都可以这样做。您可以使用pax考试进行OSGi集成测试。