0

我花了一周时间尝试将 JPA / ServiceMix 4.5.1 / camel-jpa 2.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]
[...]

我尝试了几种变体。这是我当前的配置:

持久性.xml:

<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>

骆驼上下文.xml

<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>

实体 Bean(用 groovy 编写)

@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) {
         // ...
    }
}

我尝试了多种不同的 DataSource 实现,包括 BasicDataSource、org.springframework.jdbc.datasource.SimpleDriverDataSource 和 com.mysql.jdbc.jdbc2.optional.MysqlDataSource。所有这些都会导致 IllegalArgumentException。

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

4

1 回答 1

2

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

于 2013-07-11T20:52:35.010 回答