论坛首页 Java企业应用论坛

Spring2.5+IBatis+JPA+Compass 注解应用

浏览 4308 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-02-21   最后修改:2010-02-21

新年伊始,开始复习一些旧的知识:

Spring 2.5+Ibatis+JPA+Compass整合应用

使用 lib文件如下:

 

  <classpathentry kind="lib" path="src/commons-dbcp.jar"/>
 <classpathentry kind="lib" path="src/commons-logging.jar"/>
 <classpathentry kind="lib" path="src/commons-pool.jar"/>
 <classpathentry kind="lib" path="src/compass-2.2.0.jar"/>
 <classpathentry kind="lib" path="src/IKAnalyzer.jar"/>
 <classpathentry kind="lib" path="src/lucene-analyzers.jar"/>
 <classpathentry kind="lib" path="src/lucene-core.jar"/>
 <classpathentry kind="lib" path="src/lucene-highlighter.jar"/>
 <classpathentry kind="lib" path="src/lucene-queries.jar"/>
 <classpathentry kind="lib" path="src/lucene-snowball.jar"/>
 <classpathentry kind="lib" path="src/lucene-spellchecker.jar"/>
 <classpathentry kind="lib" path="src/mysql-connector-java-3.2.0-alpha-bin.jar"/>

 

 

在Spring+Ibatis+Compasss整合事必须注意的几点:

(1)Spring和IBatis的事务的整合

(2)IBatis和Compass整合时采用的GpsDevice不同:(在Compass正对JPA,Spring,hibernate,Ibatis的GpsDevice不同配置可能不同)

 

 IBatis配置如下:

 <!--
  关于JPA的配置
 -->
 <bean id="jpaGpsDevice"
  class="org.compass.gps.device.ibatis.SqlMapClientGpsDevice">
  <property name="name">
   <value>JpaGpsDevice</value>
  </property>
  <property name="sqlMapClient"
   ref="sqlMapClient" />
   <property name="selectStatementsIds">
    <value>select blogid from blog</value>
   </property>
 </bean>

 

橘红色部分不配置的错误如下:

 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compassGps' defined in class path resource [spring-search.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: {JpaGpsDevice}: Must set selectStatementsIds property
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
 at com.vnvtrip.search.ibatis.blog.test.BlogTest.main(BlogTest.java:14)
Caused by: java.lang.IllegalArgumentException: {JpaGpsDevice}: Must set selectStatementsIds property
 at org.compass.gps.device.ibatis.SqlMapClientGpsDevice.doStart(SqlMapClientGpsDevice.java:98)
 at org.compass.gps.device.AbstractGpsDevice.start(AbstractGpsDevice.java:124)

 

其他地方配置不同的框架一样:

 

<!--
      根据dataSource和configLocation创建一个SqlMapClient
     -->
  <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">      
     <property name="configLocation" value="sql-map-config.xml"/>
      <property name="dataSource">
   <ref bean="dataSource" />
  </property>
    </bean>
 <!--
       创建SqlMapClient的模板对象
     -->
     <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
         <property name="sqlMapClient">
   <ref bean="sqlMapClient" />
   </property>
 </bean>

 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         <property name="dataSource" ref="dataSource"/>
 </bean>

 

 

Compass配置如下:
 
 <!-- 注解事物的應用 -->
 <tx:annotation-driven transaction-manager="txManager" />

 <bean id="jpaGpsDevice"
  class="org.compass.gps.device.ibatis.SqlMapClientGpsDevice">
  <property name="name">
   <value>JpaGpsDevice</value>
  </property>
  <property name="sqlMapClient"
   ref="sqlMapClient" />
   <property name="selectStatementsIds">
    <value>select blogid from blog</value>
   </property>
 </bean>

 

详细的看源代码:

 

 

 

 

 

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics