zoukankan      html  css  js  c++  java
  • spring mvc---applicationContent-mybatis.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="true">

    <!-- dbcp 连接池 -->
    <bean id="dataSourceTarget" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" >
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://127.0.0.1:3306/ssm2.0?useUnicode=true</value>
    </property>
    <property name="username" >
    <value>root</value>
    </property>
    <property name="password" >
    <value>123456</value>
    </property>
    <!-- 初始化连接数 -->
    <property name="initialSize" value="0"></property>
    <!-- 连接池最大数量 -->
    <property name="maxActive" value="20"></property>
    <!-- 连接池最大空闲 -->
    <property name="maxIdle" value="20"></property>
    <!-- 连接池最小空闲 -->
    <property name="minIdle" value="1"></property>
    <!-- 获取连接最大等待时间 -->
    <property name="maxWait" value="60000"></property>
    </bean>

    <!--  jdbcTemplate 注解注入
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource">
    <ref local="dataSourceTarget" />
    </property>
    </bean>
    <!--1:配置一个JdbcTemplate实例,并将这个“共享的”,“安全的”实例注入到不同的DAO类中去 -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
    </bean>
    -->


    <!-- 读取mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSourceTarget"></property>
    <property name="typeAliasesPackage" value="com.ssm.krystal" />
    <property name="mapperLocations" value="classpath:com/ssm/krystal/mapping/*.xml"></property>
    </bean>

    <!-- sqlSession -->
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory"/>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.ssm.krystal.*.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

    <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSourceTarget"></property>
    </bean>

    <tx:advice id="userTxAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="delete*" propagation="REQUIRED" read-only="false"
    rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException"/>
    <tx:method name="insert*" propagation="REQUIRED" read-only="false"
    rollback-for="java.lang.RuntimeException" />
    <tx:method name="update*" propagation="REQUIRED" read-only="false"
    rollback-for="java.lang.Exception" />
    <tx:method name="find*" propagation="SUPPORTS"/>
    <tx:method name="get*" propagation="SUPPORTS"/>
    <tx:method name="select*" propagation="SUPPORTS"/>
    </tx:attributes>
    </tx:advice>

    <aop:config>
    <aop:pointcut id="pc" expression="execution(public * com.ssm.krystal.*.service.*.*.*(..))" /> <!--把事务控制在Service层-->
    <aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" />
    </aop:config>
    </beans>

  • 相关阅读:
    while语句
    闭包
    文件操作
    Python基础九:高级特性
    Python基础八:函数
    Python基础六:字典和集合
    Python基础七:条件判断和循环结构
    Python基础五:列表和元组
    Python基础四:字符串及编码
    Python基础三:数据类型和变量
  • 原文地址:https://www.cnblogs.com/krystal0901/p/5517745.html
Copyright © 2011-2022 走看看