spring_config.xml
<?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"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
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 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
<!--引入springmvc配置文件,但如果web.xml扫描springmvc文件的话,此项不用配置-->
<!--<import resource="classpath:springmvc.xml"></import>-->
<!--自动扫描service层-->
<context:component-scan base-package="cn"></context:component-scan>
<!--properties文件的配置-->
<context:property-placeholder location="classpath:mail.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--配置数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
<property name="initialPoolSize" value="${initpoolsize}"/>
<property name="minPoolSize" value="${minpoolsize}"/>
<property name="maxPoolSize" value="${maxpoolsize}"/>
<property name="acquireIncrement" value="${acquireIncrement}"/>
</bean>
<!--配置事务-->
<!--事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--通知-->
<tx:advice id="message" transaction-manager="transactionManager">
<tx:attributes>
<!--read-only是否只读 propagation事务的传播行为 isolation事务的隔离级别-->
<tx:method name="select*" read-only="true" propagation="SUPPORTS" isolation="DEFAULT"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS" isolation="DEFAULT"/>
<tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
<!--AOP配置切点和通知-->
<aop:config>
<aop:pointcut id="qd" expression="within(cn.service..*)"></aop:pointcut>
<aop:advisor advice-ref="message" pointcut-ref="qd"></aop:advisor>
</aop:config>
<!--配置spring和mybatis的整合-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!--当接口和xml不在同一位置时,需配置此项-->
<property name="mapperLocations" value="classpath:mapperxml/*.xml"/>
<!--引入mybatis的配置文件-->
<property name="configLocation" value="classpath:mybatis_config.xml"/>
</bean>
<!--扫描接口-->
<mybatis:scan base-package="cn.dao"></mybatis:scan>
<!--发送邮件的配置 此id固定,不可随意更改-->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="username" value="${mail.sender.name}"/>
<property name="password" value="${mail.sender.password}"/>
<property name="host" value="${mail.host}"/>
<property name="port" value="${mail.port}"/>
<property name="protocol" value="${mail.protocol}"/>
<property name="defaultEncoding" value="utf-8"/>
<!--查看发送邮件过程的信息-->
<!--<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>-->
</bean>
</beans>
springmvc.xml
<?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="cn.controller"></context:component-scan>
<!--开启注解-->
<mvc:annotation-driven>
<mvc:path-matching suffix-pattern="false"></mvc:path-matching>
</mvc:annotation-driven>
<!--所有静态资源文件放行-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>
<!--文件上传的配置-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"/>
</bean>
<!--视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--<property name="prefix" value="/WEB-INF/"/>-->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
mybatis_config.xml
<?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="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<package name="cn.bean"/>
</typeAliases>
<!--<plugins>
<!– 配置分页插件–>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!– 合理化分页–>
<property name="reasonable" value="true"/>
<!–该参数对使用 RowBounds 作为分页参数时有效。 当该参数设置为 true 时,会将 RowBounds 中的 offset 参数当成 pageNum 使用,可以用页码和页面大小两个参数进行分页。–>
<property name="offsetAsPageNum" value="true"/>
<property name="supportMethodsArguments" value="true"/>
<property name="params" value="pageno=pageno;pagesize=pagesize;"/>
</plugin>
</plugins>-->
</configuration>
日志
#Global logging configuration
log4j.rootLogger=ERROR, stdout
#MyBatis logging configuration...
log4j.logger.cn=TRACE
#Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
log4j.appender.A1.Encoding=UTF-8
邮件
网易邮箱
mail.sender.name=邮箱地址
mail.sender.password=邮箱密码
mail.host=smtp.163.com
mail.port=25
mail.protocol=smtp
QQ邮箱
#mail.sender.name2=邮箱地址
#mail.sender.password2=邮箱密码
#mail.host2=smtp.exmail.qq.com
#mail.port2=465
#mail.protocol2=smtp
#POP3/SMTP:anruuixmxcszfjjc
#IMAP/SMTP:focrefldmqnbjaag
# bhgfqirahoydfiba
jdbc
driverClass=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/数据库名?characterEncoding=UTF-8
user=root
password=密码
initpoolsize=20
minpoolsize=20
maxpoolsize=500
acquireIncrement=10
#driverClass=oracle.jdbc.driver.OracleDriver
#url=jdbc:oracle:thin:@localhost:1521:XE
#user=hr
#password=密码
#initpoolsize=20
#minpoolsize=20
#maxpoolsize=100
#acquireIncrement=10
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">
<modelVersion>4.0.0</modelVersion>
<groupId>cn</groupId>
<artifactId>exam_sys2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!--MyBatis-Spring版本号2.0-->
<mybatis-spring.version>2.0.1</mybatis-spring.version>
<!--mybatis版本号3.5+-->
<mybatis.version>3.5.2</mybatis.version>
<!--spring版本号5.0+-->
<spring.version>5.1.5.RELEASE</spring.version>
<!--spring batch4.0+-->
<!--java8+-->
</properties>
<dependencies>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!--事务-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!---->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<!--AOP配置-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--springmvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!--spring-mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<!--servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!--数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!--<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
</dependency>-->
<!--连接池-->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!--单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!--日志-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<!--jstl-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--el表达式-->
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<!--validator数据校验-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<!--上传组件包-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<!--分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.1</version>
</dependency>
<!--jackon-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
</dependency>
<!--发送邮件-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!--导入导出 阿里-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<resources>
<!--非resources下的xml文件不会自动扫描-->
<!--<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>-->
<!--resources下的文件不会自动扫描-->
<!-- <resource>
<directory>src/main/resources/mapperxml</directory>
<includes>
<include>*.properties</include>
<include>*.json</include>
<include>*.xml</include>
<include>*.png</include>
<include>**/*.xls</include>
</includes>
<filtering>false</filtering>
</resource>-->
<!-- <resource>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>*.json</include>
<include>*.xml</include>
<include>*.png</include>
<include>**/*.xls</include>
</includes>
<filtering>false</filtering>
</resource>-->
</resources>
<plugins>
<!--tomcat7的插件-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--<path>/</path>-->
<!-- 直接访问 Tomcat 服务器的 manager -->
<url>http://localhost:8080/manager/text</url>
<!--setting里的id-->
<server>tomcat9</server>
</configuration>
</plugin>
<!--指定maven编译的jdk版本,不指定maven3默认使用jdk1.5,maven2默认1.3-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
<!--spring-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring_config.xml</param-value>
</context-param>
<!--监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--springmvc-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--字符编码过滤器-->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>