zoukankan      html  css  js  c++  java
  • applicationContext.xml

    <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">

    <context:annotation-config />

    <!-- 扫描com.liuruichao包下得所有类 -->

    <context:component-scan base-package="com.liuruichao" />


    <bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"

    destroy-method="close">

    <property name="driverClassName"value="${jdbc.driverClassName}" />

    <property name="url" value="${jdbc.url}" />

    <property name="username" value="${jdbc.username}" />

    <property name="password" value="${jdbc.password}" />

    </bean>

    <context:property-placeholder location="classpath:jdbc.properties" />


    <bean id="sessionFactory"

    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <property name="dataSource" ref="dataSource" />

    <property name="packagesToScan">

    <list>

    <value>com.liuruichao.model</value>

    </list>

    </property>

    <property name="hibernateProperties">

    <value>

    hibernate.dialect=org.hibernate.dialect.MySQLDialect

    hibernate.show_sql=true

    hibernate.format_sql=true

    hibernate.hbm2ddl.auto=update

    </value>


    </property>

    </bean>


    <bean id="transactionManager"

    class="org.springframework.orm.hibernate4.HibernateTransactionManager">

    <property name="sessionFactory" ref="sessionFactory" />

    </bean>


    <tx:annotation-driven transaction-manager="transactionManager" />


    <aop:config>

    <!--定义需要进行切面编程的所有方法,定义成为一个id是nicai的bean 代表了多有的方法 -->

    <aop:pointcut id="bussinessService"

    expression="execution (public * com.liuruichao.service.*.*(..))" />

    <!-- id是txAdvice的bean 切入 id是nicai的所有方法 把他们俩整合到一起 -->

    <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/>

    </aop:config>

    <!-- 定义一个指导意见(在某些方法执行前执行)提高效率的 代表了所要加入的切面 -->

    <tx:advice id="txAdvice" transaction-manager="transactionManager">

    <tx:attributes>

    <tx:method name="save*" propagation="REQUIRED" />

    <tx:method name="add*" propagation="REQUIRED" />

    <tx:method name="update*" propagation="REQUIRED" />

    <tx:method name="delete*" propagation="REQUIRED" />

    <tx:method name="find*" read-only="true" />

    <tx:method name="load*" read-only="true" />

    </tx:attributes>

    </tx:advice>

    </beans>

  • 相关阅读:
    Java_适配器模式
    linux常用命令整理
    (转)使用隐藏的iframe 隐藏form提交,仿AJax无刷新提交,可以实现无刷新上传文件
    mysql添加并返回主键
    学习RMI
    关于bcprov-jdk16
    JavaScript在页面中的引用方法
    通过CFX发布WebService(一)
    字符串和json数据的转换
    MD5 加密与解密
  • 原文地址:https://www.cnblogs.com/liuruichao/p/4005881.html
Copyright © 2011-2022 走看看