ServiceMix/Blueprint/JPA集成

ServiceMix/Blueprint/JPA集成,jpa,apache-camel,osgi,apache-servicemix,blueprint-osgi,Jpa,Apache Camel,Osgi,Apache Servicemix,Blueprint Osgi,我花了一周时间试图将JPA/ServiceMix4.5.1/camel JPA2.10.4/Blueprint集成在一起。我目前正在使用OpenJPA,但与之无关。servicemix使用的aries jpa版本为0.3.0 我无法通过的堆栈跟踪是: org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instanciating bean workoutEntity of class clas

我花了一周时间试图将JPA/ServiceMix4.5.1/camel JPA2.10.4/Blueprint集成在一起。我目前正在使用OpenJPA,但与之无关。servicemix使用的aries jpa版本为0.3.0

我无法通过的堆栈跟踪是:

org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instanciating bean workoutEntity of class class [...].WorkoutEntity
at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:271)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:708)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:60)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[10:org.apache.aries.blueprint:0.3.2]
[...]
Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: [javax.sql.DataSource]
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:218)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)

[...]
Caused by: java.lang.IllegalArgumentException: [javax.sql.DataSource]
at org.apache.aries.jndi.services.ServiceHelper.proxyPriviledged(ServiceHelper.java:348)
at org.apache.aries.jndi.services.ServiceHelper.access$700(ServiceHelper.java:65)
at org.apache.aries.jndi.services.ServiceHelper$1.run(ServiceHelper.java:285)
at java.security.AccessController.doPrivileged(Native Method)[:1.6.0_43]
[...]
我尝试了数据源的多种不同实现,包括BasicDataSource、org.springframework.jdbc.DataSource.SimpleDriverDataSource和com.mysql.jdbc.jdbc2.optional.MysqlDataSource。所有这些都会导致非法辩论异常


我还尝试放弃使用JNDI,而是直接在persistence.xml中定义数据源。这会导致OpenJPA包中出现ClassNotFoundException,因为它没有导入mysql驱动程序。我宁愿在camel-context.xml中定义它,也不愿意重新绑定OpenJPA jar。

您可能还需要安装aries JNDI功能。这有助于通过JNDI查找调用OSGi服务。这应该是丢失的部分

<persistence-unit name="customer1" transaction-type="JTA">
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/prototypedb)</jta-data-source>
     <class>...</class>
</persistence-unit>
<service id="PrototypeDB" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/prototypedb"/>
    </service-properties>
    <bean class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"        value="com.mysql.jdbc.Driver"/>
        <property name="url"                    value="jdbc:mysql://localhost:3306/prototype"/>
        <property name="username"               value="root"/>
        <property name="password"               value="..."/>
    </bean>
</service>

<service ref="workoutEntity" interface="..."/>
<bean id="workoutEntity" class="...">
    <jpa:unit index="0"         unitname="customer1" />
    <tx:transaction method="*"  value="Required"/>
</bean>
@Entity
@Table(name='customer1')
@Slf4j
class WorkoutEntity implements IWorkoutEntity{

    private EntityManager entityManager

    WorkoutEntity(final EntityManagerFactory entityManagerFactory) {
        this.entityManager = entityManagerFactory.createEntityManager()
    }

    @Handler
    void create( @Body final String input) {
         // ...
    }
}