0

我經歷了幾篇文章,並配置了以下內容,但是我可以看到一些交易管理問題。請讓我知道無論我是在下面的配置正確使用指南針:春天,eclipselink,指南針集成

Spring的配置

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

<bean class="org.compass.spring.support.CompassContextBeanPostProcessor"/> 

<bean id="compass" class="org.compass.spring.LocalCompassBean"> 
<property name="classMappings"> 
<list> 
<value>......</value> 
<value>......</value> 
<value>......</value> 
</list> 
</property> 
<property name="compassSettings"> 
<props> 
<prop key="compass.engine.connection">file:///usr/local/lucene</prop> 
<prop key="compass.transaction.factory"> 
org.compass.spring.transaction.SpringSyncTransactionFactory 
</prop> 
</props> 
</property> 
<property name="transactionManager" ref="transactionManager"/> 
</bean> 

指南針代碼:

private CompassSession session; 

@CompassContext 
protected void setCompassSession(CompassSession session) { 
this.session = session; 

} 

public void index(Coupon coupon) throws AppException{ 
try { 
session.save(coupon); 
} catch (CompassException exception) { 
logger.debug("Error in coupon indexing: "+ exception.getMessage()); 
} 
} 

在服務層:

@Transactional 
public void saveCoupon(Coupon coupon) throws AppException{ 
Coupon savedCoupon = dbCouponDAO.saveCoupon(coupon); // saves to db through eclipselink 
nonDbCouponDAO.index(savedCoupon); // indexes in compass 
} 

根據我的理解,配置爲eclipselink的事務管理器可以用作c ompass事務管理器,並且eclipselink和compass操作都可以在一個單元中使用,正如我在服務層中提到的那樣。

請讓我知道如果我在這裏做錯了什麼。

謝謝。

回答

1

嘗試添加此,

<!-- Search Manager using Comass abstractions. --> 
<bean class="org.compass.spring.support.CompassContextBeanPostProcessor"/> 

<bean id="compass" class="org.compass.spring.LocalCompassBean"> 
    <property name="compassSettings"> 
     <props> 
      <prop key="compass.engine.connection">file://${user.home}/indexes</prop> 
      <prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop> 
     </props> 
    </property> 
    <property name="classMappings"> 
     <list> 
      <value>MyEntity</value> 
     </list> 
    </property> 
    <property name="transactionManager"> 
     <ref local="transactionManager" /> 
    </property> 
</bean> 
<bean id="jpaGpsDevice" class="org.compass.gps.device.jpa.JpaGpsDevice"> 
    <property name="name"> 
     <value>jpaDevice</value> 
    </property> 
    <property name="entityManagerFactory"> 
     <ref local="entityManagerFactory" /> 
    </property> 
    <property name="nativeExtractor"> 
     <bean class="org.compass.gps.device.jpa.extractor.SpringNativeJpaExtractor" /> 
    </property> 
</bean> 
<bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop"> 
    <property name="compass"> 
     <ref bean="compass" /> 
    </property> 
    <property name="gpsDevices"> 
     <list> 
      <ref bean="jpaGpsDevice" /> 
     </list> 
    </property> 
</bean> 
<!-- COMPASS END --> 

讓我知道,如果這有助於。

+0

通過我的配置,我能夠透明地創建索引而無需編寫任何其他代碼。 – tara