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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="
 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
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 ">
 <context:annotation-config />  <!-- 打开注解配置-->
 <context:property-placeholder location="classpath:jdbc.properties" />    <!--读取properties配置文件 -->
 
    <!--读取properties的文件内容-->
  <bean
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <value>classpath:jdbc.properties</value>
  </property>
 </bean>
 
 
       
 <bean id="dataSource" class="${dataSource}" destroy-method="close">         <!-- 配置database信息-->
  <property name="driverClassName" value="${driverClassName}" />
  <property name="url" value="${url}" />
  <property name="username" value="${username}" />
  <property name="password" value="${password}" />
  <property name="initialSize" value="${initialSize}" />                    <!-- 刚开始启动时的链接数-->
  <property name="maxActive" value="${maxActive}" />                   <!-- 活动量最高峰时的链接数-->
  <property name="maxIdle" value="${maxIdle}" />                   <!--空闲时最大链接数 -->
  <property name="minIdle" value="${minIdle}" />                        <!--空闲时最小的连接数 -->
 </bean>
 <!-- 读取xml的配置-->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">            <!-- 生成sessionFactory并交给spring管理-->
  <property name="dataSource" ref="dataSource" />                                    <!-- 为sessionFactory注入database-->
  <property name="mappingResources">                                           <!--读取hibernate的配置文件 -->
   <list>
    <value>com/Address.hbm.xml</value>                          <!--配置文件-->
   </list>
  </property>
  <property name="hibernateProperties">                              <!--hibernate的配置属性 -->
   <value>
    hibernate.dialect=org.hibernate.dialect.SQLServerDialect            <!-- 数据库所用的sql语句-->
    hibernate.show_sql=true
    hibernate.format_sql=true
   </value>
  </property>
 </bean>
 
 
 
 <!---读取注解的配置-->
  <bean id="sf"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="ds" />
 
   <property name="packagesToScan">                      <!--注解方式扫描实体类 -->
   <list>
    <value>com.tr.jade.modles</value>            <!-- 实体类所在的包-->         
   </list>
  </property>
  <property name="hibernateProperties">                           <!-- hibernate的配置属性-->
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect                     <!-- 数据库所用的sql语句-->
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.current_session_context_class">thread</prop>

 <prop key="hibernate.cache.use_second_level_cache">true</prop>         <!--启用二级缓存-->
    <prop key="hibernate.cache.use_query_cache">false</prop>              <!--是否启动查询缓存-->
    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>    <!--指定缓存类-->
   </props>
   </props>
  </property>
 </bean>
 
 
 
 
 <bean id="txManager"                                        
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">       <!--把hibernate的sessionfactory交给spring管理-->
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 <tx:annotation-driven transaction-manager="txManager" />                     <!-- 打开以注解的方式管理事物-->
 
 
 <aop:config>
  <aop:pointcut id="bussinessService"
   expression="execution(public * com.bjsxt.registration.service.*.*(..))" />     <!--定义切面-->     
  <aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice" />              <!--给切面注入通知-->     
 </aop:config>

 <tx:advice id="txAdvice" transaction-manager="txManager">                <!--定义事物的通知-->     
  <tx:attributes>
   <tx:method name="delete*" read-only="true" propagation="REQUIRED" />
   <tx:method name="add*" propagation="REQUIRED"/>
   <tx:method name="get*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值