一、(idea省略此步) eclipse配置
- 创建maven web项目,名字为CGB-JT-SYS-V3.01
- 生成部署描述文件 web.xml
- 修改项目编码为utf-8
- 设置项目targeted runtimes (Tomcat)
- 修改项目project facets (jdk1.8)
二、添加项目依赖
- 添加Druid 连接池(两个依赖:mysql驱动,druid库文件)
- 添加Mybatis 框架(三个依赖:mybatis,mybatis-spring,spring-jdbc)
- 添加Spring MVC 模块环境(一个依赖spring-webmvc)
- 添加 jackjson库(一个依赖fastjson,用于将对象转换为json串)
- 添加Junit 单元测试依赖
- mysql-connector
三、创建root配置类(所有涉及到包扫描的类,根据自己的包路径写即可)
通过此配置类整合数据源以及mybatis等model对象的配置
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
@ComponentScan(value="com.jt",
excludeFilters={@ComponentScan.Filter(type= FilterType.ANNOTATION,classes={Controller.class, ControllerAdvice.class})})
public class AppRootConfig {//service,dao
}
四、创建测试基类
import org.junit.After;
import org.junit.Before;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class TestBase {
protected AnnotationConfigApplicationContext ctx;
@Before
public void init() {
ctx=new AnnotationConfigApplicationContext(AppRootCon