xsi:schemaLocation4.0.0cn.temptationssmwar0.0.1-SNAPSHOTssm Maven Webapp${spring.version}org.springframeworkspring-aop${spring.version}org.springframeworkspring-web${spring.version}org.springframeworkspring-webmvc${spring.version}org.springframeworkspring-jdbc${spring.version}org.springframeworkspring-tx${spring.version}org.aspectjaspectjrt1.8.0org.aspectjaspectjweaver1.8.0org.mybatismybatis3.3.0mysqlmysql-connector-java5.1.26com.alibabadruid1.0.20org.mybatismybatis-spring1.2.3javax.servletjstl1.2log4jlog4j1.2.17org.slf4jslf4j-api1.7.21junitjunit3.8.1testssmorg.apache.maven.pluginsmaven-compiler-plugin1.81.8
保存后,可以看到相关jar包被下载至本地仓库
7、完善项目结构因为服务端maven项目的标准结构有四个子包:src/main/java、src/main/resources、src/test/java、src/test/resources,这里缺少了src/test/resources,所以手动补上。
在项目中新建Source Folder
创建src/test/resources目录后,工程如下图所示
右键查看项目属性,点击Deployment Assembly,移除test和target
移除后如下图
8、创建项目用的配置文件
创建log4j.properties文件,内容如下:
#USE THIS SETTING FOR OUTPUT MYBATIS`s SQL ON THE CONSOLE log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
创建mybatis-config.xml文件,内容如下:
DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"
创建spring-mvc.xml文件,内容如下:
xmlns:xsi xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc/spring-mvc.xsd" class
创建spring-mybatis.xml文件,内容如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans/spring-beans.xsd"
创建spring-tx.xml文件,内容如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx/spring-tx.xsd" 为切入点方法添加事务详情 name:方法名,*表示任意方法名称 propagation:设置传播行为 isolation:设置隔离级别 read-only:是否只读
修改web.xml文件,内容如下: