SSM Spring SpringMVC MyBatis简单整合 案例:转账
maven java包
SQL表
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ssm_parent</artifactId>
<groupId>com.hrh.ssm</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ssm_demo4</artifactId>
<packaging>war</packaging>
<dependencies>
<!--持久层-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--业务层-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<!--web层-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!--配置tomcat插件-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>80</port>
</configuration>
</plugin>
</plugins>
</build>
</project>
MyBatis
mybatis-config.xml
- 设置setting标签 (驼峰标识 二级缓存 自动映射 延迟加载等)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!--驼峰标识-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!--延迟加载-->
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
<!--自动映射范围-->
<setting name="autoMappingBehavior" value="FULL"/>
</settings>
</configuration>
applicationContext_dao.xml
- 导入外部jdbc配置文件
- 配置连接池
- 将sqlSessionFactory交给IOC容器管理(四个属性)
- 扫描接口包,mybatis动态代理mapper接口后,将代理交给spring管理
<?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"
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">
<!--导入外部jdbc配置文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--配置连接池-->
<bean id="druid" class="com.alibaba.druid.pool.DruidDataSource">
<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>
<!--sqlSessionFactory放到IOC中-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="druid"/>
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
<property name="typeAliasesPackage" value="com.hrh_ssm.pojo"/>
<property name="mapperLocations" value="classpath:mybatis/mapper/*Mapper.xml"/>
</bean>
<!--扫描接口包 创建动态代理 spring管理-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.hrh_ssm.mapper"/>
</bean>
</beans>
XXXMapper.xml
- namespace和接口限定路径一致
- 编写sql语句,每个sql语句对应一个mapper接口的方法,对应一个statement
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hrh_ssm.mapper.AccountMapper">
<!--对应接口中的方法-->
<update id="out">
update account set money=money-#{money} where name=#{name};
</update>
<update id="in">
update account set money=money+#{money} where name=#{name};
</update>
</mapper>
XXXMapper.java 接口
package com.hrh_ssm.mapper;
import org.apache.ibatis.annotations.Param;
public interface AccountMapper {
//出账
public void out(@Param("name") String name, @Param("money") double money);
//入账
public void in(@Param("name") String name, @Param("money") double money);
}
Spring
applicationContext_service.xml
- 注解扫描service包
- 设置事务驱动 tx标签 transactionManager关联applicationContext_dao中的连接池
<?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"
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">
<!--扫描service包-->
<context:component-scan base-package="com.hrh_ssm.service.impl"/>
<!--事务管理器 注入连接池-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="druid"/>
</bean>
<!--设置事务驱动 注入事务管理器-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
XXXService.java 接口及实现类
package com.hrh_ssm.service;
public interface AccountService {
public void transfer(String outName,String inName,double money);
}
package com.hrh_ssm.service.impl;
import com.hrh_ssm.mapper.AccountMapper;
import com.hrh_ssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class AccountServiceImpl implements AccountService {
@Autowired
private AccountMapper accountMapper;
//转账 并添加事务注解
@Transactional
public void transfer(String outName, String inName, double money) {
accountMapper.out(outName,money);
//测试事务
//int a=1/0;
accountMapper.in(inName,money);
}
}
SpringMVC
applicationContext_mvc.xml
- 注解扫描controller包
- 开启注解驱动 自动配置处理器映射器和处理器适配器
- 配置视图解析器
<?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:mvc="http://www.springframework.org/schema/mvc"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描controller包注解-->
<context:component-scan base-package="com.hrh_ssm.controller"/>
<!--自动配置处理器映射器和处理器适配器-->
<mvc:annotation-driven/>
<!--配置视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
XXXController.java
package com.hrh_ssm.controller;
import com.hrh_ssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
//设置访问此controller的URL
@RequestMapping("account")
public class AccountController {
@Autowired
private AccountService accountService;
//设置访问此方法的URL和需传递的参数,并限定提交方法
@RequestMapping(value = "transfer",params = {"outName","inName","money"},method = {RequestMethod.GET,RequestMethod.POST})
public ModelAndView transfer(@RequestParam("outName") String outName,
@RequestParam("inName") String inName,
@RequestParam("money") double money){
//调用业务层处理
accountService.transfer(outName,inName,money);
String msg=outName+"..."+inName+"..."+money;
ModelAndView mv = new ModelAndView("testAccount");
mv.addObject("msg",msg);
return mv;
}
}
响应的jsp
<%--
Created by IntelliJ IDEA.
User: QuietHR
Date: 2018/9/10
Time: 10:45
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${msg}</h1>
</body>
</html>
web.xml
- 设置全局参数 配置application_*.xml的映射
- 监听器监听ContextLoaderListener 服务器启动即创建IOC容器
- 配置DispatcherServlet ( 配置servlet参数 关联applicationContext_mvc.xml 设置服务器启动即加载Servlet)
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!--全局参数 配置IOC.xml路径 实例化IOC的路径-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext_service.xml,
classpath:mybatis/applicationContext_dao.xml
</param-value>
</context-param>
<!--监听context 服务器启动就创建IOC容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--配置springmvc的配置文件路径-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc/applicationContext_mvc.xml</param-value>
</init-param>
<!--设置服务器启动后 立即实例化此servlet-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.hrh</url-pattern>
</servlet-mapping>
</web-app>
测试
解析控制台日志输出
2018-09-10 15:30:11,669 [http-bio-80-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] DispatcherServlet with name 'springmvc' processing GET request for [/ssm_demo5/account/transfer.hrh]
2018-09-10 15:30:11,672 [http-bio-80-exec-2] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Looking up handler method for path /account/transfer.hrh
2018-09-10 15:30:11,673 [http-bio-80-exec-2] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[DEBUG] Returning handler method [public org.springframework.web.servlet.ModelAndView com.hrh.controller.AccountController.transfer(java.lang.String,java.lang.String,double)]
2018-09-10 15:30:11,673 [http-bio-80-exec-2] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'accountController'
2018-09-10 15:30:11,674 [http-bio-80-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Last-Modified value for [/ssm_demo5/account/transfer.hrh] is: -1
2018-09-10 15:30:11,687 [http-bio-80-exec-2] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0'
2018-09-10 15:30:11,690 [http-bio-80-exec-2] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'transactionManager'
2018-09-10 15:30:11,694 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Creating new transaction with name [com.hrh.service.impl.AccountServiceImpl.transfer]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2018-09-10 15:30:11,734 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] incremented pending_acquires: 1
2018-09-10 15:30:11,734 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] incremented pending_acquires: 2
2018-09-10 15:30:11,735 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] incremented pending_acquires: 3
2018-09-10 15:30:11,735 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] com.mchange.v2.resourcepool.BasicResourcePool@4d36468f config: [start -> 3; min -> 3; max -> 15; inc -> 3; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 0; mox_resource_age -> 0; max_idle_time -> 0; excess_max_idle_time -> 0; destroy_unreturned_resc_time -> 0; expiration_enforcement_delay -> 0; break_on_acquisition_failure -> false; debug_store_checkout_exceptions -> false]
2018-09-10 15:30:11,736 [http-bio-80-exec-2] [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource]-[INFO] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hgesl09x1hxol10rw1wd9|2fcb3215, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgesl09x1hxol10rw1wd9|2fcb3215, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/spring_day03?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
2018-09-10 15:30:11,736 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] acquire test -- pool size: 0; target_pool_size: 3; desired target? 1
2018-09-10 15:30:11,737 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] awaitAvailable(): [unknown]
2018-09-10 15:30:11,737 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 0, unused: 0, excluded: 0]
2018-09-10 15:30:11,960 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool]-[DEBUG] com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@6d0b7776.acquireResource() returning.
2018-09-10 15:30:11,960 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool]-[DEBUG] com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@6d0b7776.acquireResource() returning.
2018-09-10 15:30:11,960 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] [com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool]-[DEBUG] com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@6d0b7776.acquireResource() returning.
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 1, unused: 1, excluded: 0]
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] decremented pending_acquires: 2
2018-09-10 15:30:11,961 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 1, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@753cf957)
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 2, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@753cf957)
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] decremented pending_acquires: 1
2018-09-10 15:30:11,961 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Acquired Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@c008085] for JDBC transaction
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@753cf957)
2018-09-10 15:30:11,961 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] decremented pending_acquires: 0
2018-09-10 15:30:11,965 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Switching JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@c008085] to manual commit
2018-09-10 15:30:11,971 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Creating a new SqlSession
2018-09-10 15:30:11,975 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:11,980 [http-bio-80-exec-2] [org.mybatis.spring.transaction.SpringManagedTransaction]-[DEBUG] JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@c008085] will be managed by Spring
2018-09-10 15:30:11,985 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.out]-[DEBUG] ==> Preparing: update account set money=money-? where name=?;
2018-09-10 15:30:12,015 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.out]-[DEBUG] ==> Parameters: 100.0(Double), aaa(String)
2018-09-10 15:30:12,024 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.out]-[DEBUG] <== Updates: 1
2018-09-10 15:30:12,024 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:12,025 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7] from current transaction
2018-09-10 15:30:12,025 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.in]-[DEBUG] ==> Preparing: update account set money=money+? where name=?;
2018-09-10 15:30:12,025 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.in]-[DEBUG] ==> Parameters: 100.0(Double), bbb(String)
2018-09-10 15:30:12,025 [http-bio-80-exec-2] [com.hrh.mapper.AccountMapper.in]-[DEBUG] <== Updates: 1
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6da58bd7]
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Initiating transaction commit
2018-09-10 15:30:12,026 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Committing JDBC transaction on Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@c008085]
2018-09-10 15:30:12,067 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Releasing JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@c008085] after transaction
2018-09-10 15:30:12,067 [http-bio-80-exec-2] [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Returning JDBC Connection to DataSource
2018-09-10 15:30:12,068 [http-bio-80-exec-2] [com.mchange.v2.resourcepool.BasicResourcePool]-[DEBUG] trace com.mchange.v2.resourcepool.BasicResourcePool@4d36468f [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@753cf957)
2018-09-10 15:30:12,072 [http-bio-80-exec-2] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Invoking afterPropertiesSet() on bean with name 'testTransfer'
2018-09-10 15:30:12,072 [http-bio-80-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Rendering view [org.springframework.web.servlet.view.JstlView: name 'testTransfer'; URL [/WEB-INF/views/testTransfer.jsp]] in DispatcherServlet with name 'springmvc'
2018-09-10 15:30:12,072 [http-bio-80-exec-2] [org.springframework.web.servlet.view.JstlView]-[DEBUG] Added model object 'msg' of type [java.lang.String] to request in view with name 'testTransfer'
2018-09-10 15:30:12,076 [http-bio-80-exec-2] [org.springframework.web.servlet.view.JstlView]-[DEBUG] Forwarding to resource [/WEB-INF/views/testTransfer.jsp] in InternalResourceView 'testTransfer'
2018-09-10 15:30:12,123 [http-bio-80-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request
2018-09-10 15:30:12,124 [http-bio-80-exec-2] [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Returning cached instance of singleton bean 'sqlSessionFactory'
Process finished with exit code 1
1 名字为springmvc的dispatcherServlet处理来自URL的get请求(localhost/account/transfer.hrh)
2 RequestMappingHandlerMapping查找处理程序的方法(/account/transfer.hrh)
3 RequestMappingHandlerMapping返回处理程序的方法(public ModerAndView transfer)
4 DefaultListableBeanFactory返回单例bean的缓存实例(accountController)
5 DefaultListableBeanFactory返回单例bean的缓存实例(transactionManager)
6 DataSourceTransactionManager创建一个新的事务:传播行为隔离级别默认(AccountServiceImpl.transfer)连接池只初始化一次
7 BasicResourcePool配置config 初始化连接池
8 ThreadPoolAsynchronousRunner处理连接池
9 DataSourceTransactionManager切换JDBC连接为手动提交(conn.setAutoCommit(false))
10 SqlSessionUtils创建一个sqlsession
11 SqlSessionUtils给sqlsession注册同步事务
12 SpringManagedTransaction JDBC连接将由Spring管理
13 AccountMapper.out 执行out方法
14 SqlSessionUtils释放事务
15 SqlSessionUtils从当前事务获取SqlSession
16 AccountMapper.in 执行in方法
17 SqlSessionUtils释放事务
18 SqlSessionUtils提交SqlSession的事务同步
19 SqlSessionUtils取消注册SqlSession的事务同步
20 SqlSessionUtils事务同步关闭SqlSession
21 DataSourceTransactionManager启动事务提交
22 DataSourceTransactionManager在连接上提交JDBC事务
23 DataSourceTransactionManager提交事务后释放JDBC连接
24 DataSourceUtils把JDBC连接放回到连接池jsp在第一次访问时执行(相当于初始化)
25 DefaultListableBeanFactory 执行testTransfer的afterPropertiesSet方法26 DispatcherServlet 在名为“springmvc”的DispatcherServlet中呈现视图名称为'testTransfer';URL(/web-inf/views/testTransfer)的jsp
27 JstlView 请求在视图名称为'testTransfer'的视图中添加String类型的msg
28 JstlView 转发到/WEB-INF/views/testTransfer.jsp
29 DispatcherServlet 成功完成请求
30 DefaultListableBeanFactory 返回单例bean sqlSessionFactory 的缓存实例