Hibernate3.2 +Spring 2.5 +Compass2.0 整合搜索引用

     昨天有网友在我的博客中,针对JPA+Spring 2.5 +Compass2.0 整合搜索引用,应用提出一些问题:

但是我们实际中常用的为:Hibernate3.2 +Spring 2.5 +Compass2.0 整合搜索。

 

Spring2.5中Spring和Hibernate的配置应用:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
      
 <!-- support annotation config -->
 <context:annotation-config/>
 <context:component-scan base-package="cn.com.unutrip.compass.search">
  <context:include-filter type="regex" expression=".model..*"/>
  <context:include-filter type="regex" expression=".dao..*"/>
  <context:include-filter type="regex" expression=".services..*"/>
  <context:include-filter type="regex" expression=".facade..*"/>
 </context:component-scan>
      
      
 <bean id="datasource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.mysql.jdbc.Driver">
  </property>
  <property name="url"
   value="jdbc:mysql://localhost:3306/search">
  </property>
  <property name="username" value="root"></property>
  <property name="password" value="123456"></property>
 </bean>
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource">
   <ref bean="datasource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
    <!--设置二级缓冲-->
    <prop key="hibernate.cache.provider_class">
     org.hibernate.cache.EhCacheProvider
    </prop>
    <!--设置二级缓冲,打开查询缓冲-->
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <!--设置显示Hibernate操作的SQL语句-->
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.schema_update">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
   </props>
  </property>
  <property name="annotatedClasses">
   <list>
    <value>cn.com.unutrip.compass.search.model.Blog</value>
   </list>
  </property>
 </bean>
 <!-- 配置事务管理器 --> 
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="sessionFactory"/>
  </property>
 </bean>
    <!-- 配置事务特性 ,配置add、delete和update开始的方法,事务传播特性为required-->      
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
     <tx:attributes>
      <tx:method name="insert*" propagation="REQUIRED"/>
      <tx:method name="delete*" propagation="REQUIRED"/>
      <tx:method name="update*" propagation="REQUIRED"/>
      <tx:method name="*" read-only="true"/>
     </tx:attributes>
    </tx:advice>
</beans>

 

compass 的配置如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation=" http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
 default-lazy-init="true">
 <bean id="annotationConfiguration"
  class="org.compass.annotations.config.CompassAnnotationsConfiguration">
 </bean>
 <bean id="compass" class="org.compass.spring.LocalCompassBean">
  <property name="resourceDirectoryLocations">
   <list>
    <value>
     classpath:cn/com/unutrip/compass/search/model
    </value>
   </list>
  </property>
  <property name="classMappings">
   <list>
    <value>cn.com.unutrip.compass.search.model.Blog</value>
   </list>
  </property>
  <property name="compassConfiguration"
   ref="annotationConfiguration" />
  <property name="compassSettings">
   <props>
    <prop key="compass.transaction.factory">
     org.compass.spring.transaction.SpringSyncTransactionFactory
    </prop>
    <prop
     key="compass.engine.analyzer.MMAnalyzer.CustomAnalyzer">
     org.mira.lucene.analysis.IK_CAnalyzer
    </prop>
    <!-- 定义索引的存储位置  -->
    <prop key="compass.engine.connection">d:/compass</prop>
   </props>
  </property>
  <property name="transactionManager" ref="transactionManager" />
 </bean>

 <bean id="hibernateGpsDevice"
  class="org.compass.spring.device.hibernate.dep.SpringHibernate3GpsDevice">
  <property name="name">
   <value>hibernateDevice</value>
  </property>
  <property name="sessionFactory" ref="sessionFactory" />
  <property name="mirrorDataChanges">
   <value>true</value>
  </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="hibernateGpsDevice" />
   </list>
  </property>
 </bean>
 <bean id="compassTemplate"
  class="org.compass.core.CompassTemplate">
  <property name="compass" ref="compass" />
 </bean>

 <!-- 定时重建索引(利用quartz)或随Spring ApplicationContext启动而重建索引 -->
 <bean id="compassIndexBuilder"
  class="cn.com.unutrip.compass.search.utils.CompassIndexBuilder"
  lazy-init="false">
  <property name="compassGps" ref="compassGps" />
  <property name="buildIndex" value="true" />
  <property name="lazyTime" value="10" />
 </bean>
</beans>

 

类库如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
 <classpathentry kind="lib" path="lib/commons-beanutils-1.8.0.jar"/>
 <classpathentry kind="lib" path="lib/commons-dbcp.jar"/>
 <classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
 <classpathentry kind="lib" path="lib/commons-logging.jar"/>
 <classpathentry kind="lib" path="lib/commons-pool.jar"/>
 <classpathentry kind="lib" path="lib/compass-2.2.0.jar"/>
 <classpathentry kind="lib" path="lib/IKAnalyzer.jar"/>
 <classpathentry kind="lib" path="lib/lucene-analyzers.jar"/>
 <classpathentry kind="lib" path="lib/lucene-core.jar"/>
 <classpathentry kind="lib" path="lib/lucene-highlighter.jar"/>
 <classpathentry kind="lib" path="lib/lucene-queries.jar"/>
 <classpathentry kind="lib" path="lib/lucene-snowball.jar"/>
 <classpathentry kind="lib" path="lib/lucene-spellchecker.jar"/>
 <classpathentry kind="lib" path="lib/mysql-connector-java-3.2.0-alpha-bin.jar"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_AOP"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_CORE"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_PERSISTENCE_CORE"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_PERSISTENCE_JDBC"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_PERSISTENCE_JDO"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_PERSISTENCE_IBATIS"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_REMOTING"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_SUPPORT"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_TESTING"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_J2EE"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_CORE"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_EXTRAS"/>
 <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_EM"/>
 <classpathentry kind="output" path="bin"/>
</classpath>

你可能感兴趣的:(eclipse,spring,Hibernate,bean,MyEclipse)