前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >S2S3H4框架深度集成搭建(3) hi

S2S3H4框架深度集成搭建(3) hi

作者头像
py3study
发布2020-01-08 18:16:13
2490
发布2020-01-08 18:16:13
举报
文章被收录于专栏:python3python3

之前分别写了集成struts2,以及spring3的关键问题,就剩hibernate4了,但是其中并不需要什么特殊的地方。只是将hibernate的配置全部转换到spring的配置中去而已。网上搜一搜有大量的技术文章,我这里就不详细赘述了,只是将本人的配置文件内容贴出来供大家参考:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       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-3.0.xsd  
           http://www.springframework.org/schema/tx   
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
           http://www.springframework.org/schema/aop   
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"  
           default-lazy-init="true" default-autowire="byName"> 
           
    <import resource="datasource-config.xml"/>   
    <import resource="hibernate-properties.xml"/> 
    <import resource="transaction-config.xml"/>   
    <import resource="application-project.xml"/>     
    <import resource="../../resource/bean/base.xml"/>   
</beans> 

上面配置部分,引用了多个其他配置,这个文件也就是我得主配置文件,第一个导入,是数据源,第二个是hibernate的属性以及映射配置,第三个是将事务叫给spring管理的配置。其他的事项目级别的配置,以及业务部分开发的基础配置,咱们只关注与hibernate相关的配置,如下:

代码语言:javascript
复制
数据源配置,本人使用的proxool连接池     
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">     
        <property name="driverClassName">     
            <value>org.logicalcobwebs.proxool.ProxoolDriver</value>     
        </property>     
        <property name="url">     
            <value>proxool.core</value>     
        </property>     
    </bean>        
hibernate的属性以及映射配置  
 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
        <property name="dataSource" ref="dataSource"/> 
        <property name="mappingResources"> 
            <list> 
                <value>com/xk/model/XkBaseCity.hbm.xml</value> 
                <value>com/xk/model/XkBaseProvince.hbm.xml</value> 
                <value>com/xk/model/XkSystemDate.hbm.xml</value> 
                <value>com/xk/model/XkTrain.hbm.xml</value> 
            </list> 
        </property> 
        <property name="hibernateProperties"> 
            <props> 
                <prop key="hibernate.show_sql">true</prop> 
                <prop key="hibernate.format_sql">false</prop> 
                <prop key="hibernate.jdbc.use_scrollable_resultset">false</prop> 
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>   
            </props> 
        </property> 
    </bean>     
 
下面是事务管理配置:  
 <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
        <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 
 
    <aop:config> 
        <aop:pointcut id="pointcutMethods" expression="execution(* com.xk..boimpl.*Impl.*(..))"/> 
        <aop:advisor advice-ref="transactionAdvice" pointcut-ref="pointcutMethods"/> 
    </aop:config> 
      
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> 
        <tx:attributes> 
            <tx:method name="get*" read-only="true" propagation="REQUIRED" /> 
            <tx:method name="find*" read-only="true" propagation="REQUIRED" /> 
            <tx:method name="query*" read-only="true" propagation="REQUIRED" /> 
            <tx:method name="add*" propagation="REQUIRED" /> 
            <tx:method name="set*" propagation="REQUIRED" /> 
            <tx:method name="put*" propagation="REQUIRED" /> 
            <tx:method name="save*" propagation="REQUIRED" /> 
            <tx:method name="update*" propagation="REQUIRED" /> 
            <tx:method name="delete*" propagation="REQUIRED" /> 
            <tx:method name="*" read-only="true" propagation="REQUIRED"/> 
        </tx:attributes> 
    </tx:advice>  
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档