ssh框架整合之配置文件

1、约束、这个就不用多说了

<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd             
       http://www.springframework.org/schema/tx     
       http://www.springframework.org/schema/tx/spring-tx.xsd 
       http://www.springframework.org/schema/aop     
       http://www.springframework.org/schema/aop/spring-aop.xsd">
        

2、整合hibernate

      所有的数据库连接都依赖于底层的连接,所以我们首先要配置一个连接池

   这里配置c3p0连接

<context:property-placeholder location="classpath:dq.properties"/>//这里是读取外部的连接jdbc_properties配置文件
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${jdbc.driverClass}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <property name="user" value="${jdbc.name}"/>
            <property name="password" value="${jdbc.password}"/>
    </bean>

然后配置sessionFactory

        <!--配置sessionFactory-->
        <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
                <!--注入连接池-->
                <property name="dataSource" ref="dataSource"/>
                <!--注入hibernate属性-->
                <property name="hibernateProperties">
                        <props>
                                <!--方言-->
                                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                                <!--建表方式-->
                                <prop key="hibernate.hbm2ddl.auto">update</prop>
                                <!--sql语句显示可选-->
                                <prop key="hibernate.format_sql">true</prop>
                                <prop key="hibernate.show_sql">true</prop>
                        </props>
                </property>
                <!--扫描包下的所有hibernate映射文件-->
                <property name="mappingDirectoryLocations" value="classpath:bean"/>
        </bean>

然后配置会用到的事务

     事务底层是依赖于sessionFactory的

        <!--事务管理器-->
        <bean name="hibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory"/>
        </bean>

最后配置事务的作用范围,也就是Spring中的aop技术

        <!--配置通知-->
        <tx:advice id="MyAdvice" transaction-manager="hibernateTransactionManager">
                <tx:attributes>
                        <tx:method name="get*" isolation="DEFAULT" read-only="true" propagation="REQUIRED"/>
                        <tx:method name="add*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                        <tx:method name="del*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                        <tx:method name="modify*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                        <!--常用开发两套-->
                        <tx:method name="query*" isolation="DEFAULT" read-only="true" propagation="REQUIRED"/>
                        <tx:method name="increase*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                        <tx:method name="remove*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                        <tx:method name="update*" isolation="DEFAULT" read-only="false" propagation="REQUIRED"/>
                </tx:attributes>
        </tx:advice>
        <!--将通知织入切点-->
        <aop:config>
                <aop:pointcut id="Mypt" expression="execution(* cn.hd.service.impl.*ServiceImpl.*(..))"/>
                <aop:advisor advice-ref="MyAdvice" pointcut-ref="Mypt"/>
        </aop:config>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值