-
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- bean>
- <tx:annotation-driven transaction-manager="transactionManager"/>
- "1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:task="http://www.springframework.org/schema/task"
- 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/task
- http://www.springframework.org/schema/task/spring-task.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
-
- <context:property-placeholder location="classpath:jdbc.properties"/>
-
- <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
- <property name="driverClassName" value="${jdbc.driver}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
-
- <property name="initialSize" value="${jdbc.initialSize}"/>
-
- <property name="maxActive" value="${jdbc.maxActive}"/>
- bean>
-
- <bean class="org.mybatis.spring.SqlSessionFactoryBean">
-
- <property name="dataSource" ref="dataSource"/>
-
- <property name="mapperLocations" value="classpath:mapper/*.xml"/>
- <property name="configLocation" value="classpath:mybatis-config.xml"/>
- <property name="typeAliasesPackage" value="com.pro.domain"/>
-
- <property name="plugins">
- <array>
- <bean class="com.github.pagehelper.PageInterceptor">
- <property name="properties">
-
- <value>
-
- helperDialect=mysql
- value>
- property>
- bean>
- array>
- property>
- bean>
-
-
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.pro.dao"/>
- bean>
-
-
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- bean>
- <tx:annotation-driven transaction-manager="transactionManager"/>
-
-
- <context:component-scan base-package="com.pro"/>
- <mvc:annotation-driven/>
- <mvc:default-servlet-handler/>
- <bean id="FreeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
- <property name="templateLoaderPath" value="/WEB-INF/ftl"/>
- <property name="freemarkerSettings">
- <props>
- <prop key="defaultEncoding">UTF-8prop>
- props>
- property>
- bean>
-
- <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
-
- <property name="contentType" value="text/html.charset=utf-8"/>
- <property name="suffix" value=".ftl"/>
- bean>
-
- beans>
- "1.0" encoding="UTF-8" ?>
- configuration
- PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
- <configuration>
- <settings>
-
- <setting name="mapUnderscoreToCamelCase" value="true"/>
- settings>
- configuration>
- <packaging>warpackaging>
- <dependencies>
-
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-testartifactId>
- <version>5.2.16.RELEASEversion>
- dependency>
- <dependency>
- <groupId>junitgroupId>
- <artifactId>junitartifactId>
- <version>4.12version>
- dependency>
-
-
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-webmvcartifactId>
- <version>5.1.9.RELEASEversion>
- dependency>
-
-
- <dependency>
- <groupId>org.freemarkergroupId>
- <artifactId>freemarkerartifactId>
- <version>2.3.30version>
- dependency>
-
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-context-supportartifactId>
- <version>5.2.6.RELEASEversion>
- dependency>
-
-
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-jdbcartifactId>
- <version>5.1.9.RELEASEversion>
- dependency>
-
-
-
-
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatisartifactId>
- <version>3.5.7version>
- dependency>
-
- <dependency>
- <groupId>org.mybatisgroupId>
- <artifactId>mybatis-springartifactId>
- <version>2.0.3version>
- dependency>
-
-
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>druidartifactId>
- <version>1.1.14version>
- dependency>
-
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>javax.servlet-apiartifactId>
- <version>3.1.0version>
- dependency>
-
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>jsp-apiartifactId>
- <version>2.0version>
- dependency>
-
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>5.1.49version>
- dependency>
-
-
- <dependency>
- <groupId>javax.servletgroupId>
- <artifactId>jstlartifactId>
- <version>1.2version>
- dependency>
-
-
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>fastjsonartifactId>
- <version>1.2.47version>
- dependency>
-
-
- <dependency>
- <groupId>com.fasterxml.jackson.coregroupId>
- <artifactId>jackson-coreartifactId>
- <version>2.9.9version>
- dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.coregroupId>
- <artifactId>jackson-annotationsartifactId>
- <version>2.9.9version>
- dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.coregroupId>
- <artifactId>jackson-databindartifactId>
- <version>2.9.9version>
- dependency>
-
-
- <dependency>
- <groupId>com.github.jsqlparsergroupId>
- <artifactId>jsqlparserartifactId>
- <version>2.0version>
- dependency>
-
-
- <dependency>
- <groupId>com.github.pagehelpergroupId>
- <artifactId>pagehelperartifactId>
- <version>5.1.10version>
- dependency>
-
-
- <dependency>
- <groupId>ch.qos.logbackgroupId>
- <artifactId>logback-classicartifactId>
- <version>1.2.3version>
- dependency>
- dependencies>
@RunWith注解的作用
@RunWith就是一个运行器
@RunWith(JUnit4.class)就是指用JUnit4来运行
@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
@RunWith(Suite.class)的话就是一套测试集合,
- package com.pro.service;
-
- import junit.framework.TestCase;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
- //测试的注解RunWith
- @RunWith(SpringJUnit4ClassRunner.class)
- @ContextConfiguration(locations = {"classpath:applicationContext.xml"})
- public class TestServiceTest extends TestCase {
-
- //因为我们是测试springMvc,所以需要通过注入的方式,故不能直接使用Junit来测试,
- @Autowired
- private TestService testService;
-
- @Test
- public void save(){
- com.pro.domain.Test t = new com.pro.domain.Test();
- t.setContent("测试xxxxx");
- testService.save(t);
- }
- }