2013-07-09 90 views
0

我是ServiceMix/JPA/Camel/Spring的新手。我試圖將camel-jpa組件用作駱駝路線的一部分。我正在使用最新版本的ServiceMix,它是4.5.1。這使用駱駝2.10.4和春天3.0.7。ServiceMix/JPA集成 - LocalContainerEntityManagerFactoryBean類型EntityManagerFactory

更新OSGi的清單和部署一些額外的模塊,以ServiceMix的之後,我被困在下面的堆棧跟蹤:

org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: entityManagerFactory, getter: class org.springframework.orm.jpa.JpaTransactionManager.getEntityManagerFactory(, setter: [class org.springframework.orm.jpa.JpaTransactionManager.setEntityManagerFactory(interface javax.persistence.EntityManagerFactory] 
[...] 
Caused by: java.lang.Exception: Unable to convert value org[email protected]46e9e26a to type javax.persistence.EntityManagerFactory 
at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:172)[10:org.apache.aries.blueprint:0.3.2] 
at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:373)[10:org.apache.aries.blueprint:0.3.2] 
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:322)[10:org.apache.aries.blueprint:0.3.2] 
at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:555)[10:org.apache.aries.blueprint:0.3.2] 
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:306)[10:org.apache.aries.blueprint:0.3.2] 
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:819)[10:org.apache.aries.blueprint:0.3.2] 

我已經與我的persistence.xml,駱駝context.xml中玩耍了(藍圖/春天xml)並沒有取得很大進展。我現在的配置是:

駱駝的context.xml

<bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName"  value="com.mysql.jdbc.Driver"/> 
    <property name="url"     value="jdbc:mysql://localhost/prototype"/> 
    <property name="username"    value="...."/> 
    <property name="password"    value="...."/> 
</bean> 

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource"    ref="mysqlDataSource"/> 
    <property name="persistenceUnitName" value="customer1"/> 
    <property name="loadTimeWeaver"> 
     <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" /> 
    </property> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"> 
      <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.MySQLDictionary" /> 
      <property name="showSql"   value="true"/> 
     </bean> 
    </property> 
</bean> 

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

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
    <property name="transactionManager"  ref="jpaTxManager"/> 
</bean> 

的persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 
     version="2.0"> 
<persistence-unit name="customer1" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> 
    <class>....</class> 
</persistence-unit> 

任何幫助,將不勝感激。現在我已經解決了這個問題幾天了。

回答

0

由於您已經在使用Aries JPA和JTA功能的Blueprint是您所需要的。 爲此,您還需要安裝這些功能(JPA/JTA),並確保您的事務處理類型爲JTA,並且使用白羊座的實體管理器而不是彈簧,您應該保持安全。 DAO看起來更像以下內容:

<bean id="daoBean" class="dummy.class.name.DaoBean"> 
    <jpa:context property="em" unitname="customer1" /> 
    <tx:transaction method="*" value="Required" /> 
</bean> 

爲了使此功能正常工作,您需要引用相應的藍圖模式。

+0

隨着一些額外的資源幫助我瞭解如何使用藍圖/白羊座JPA功能。我已經過去了這個錯誤,但現在我堅持IllegalArgumentException。我創建了一個單獨的線程:http://stackoverflow.com/questions/17597941/servicemix-blueprint-jpa-integration – scubadev

相關問題