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" >
< context-param>
< param-name> log4jConfigLocation</ param-name>
< param-value> classpath:log4j.properties</ param-value>
</ context-param>
< listener>
< listener-class> org.springframework.web.util.Log4jConfigListener</ listener-class>
</ listener>
< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener</ listener-class>
</ listener>
< context-param>
< param-name> contextConfigLocation</ param-name>
< param-value> classpath:applicationContext.xml</ param-value>
</ context-param>
< servlet>
< servlet-name> springmvc</ servlet-name>
< servlet-class>
org.springframework.web.servlet.DispatcherServlet
</ servlet-class>
< init-param>
< param-name> contextConfigLocation</ param-name>
< param-value> classpath:springmvc-config.xml</ param-value>
</ init-param>
< load-on-startup> 1</ load-on-startup>
</ servlet>
< servlet-mapping>
< servlet-name> springmvc</ 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>
</ filter>
< filter-mapping>
< filter-name> characterEncodingFilter</ filter-name>
< url-pattern> /*</ url-pattern>
</ filter-mapping>
< jsp-config>
< jsp-property-group>
< url-pattern> *.jsp</ url-pattern>
< el-ignored> false</ el-ignored>
< scripting-invalid> true</ scripting-invalid>
< include-prelude> /page/taglib.jsp</ include-prelude>
</ jsp-property-group>
</ jsp-config>
< error-page>
< error-code> 404</ error-code>
< location> /404.html</ location>
</ error-page>
< welcome-file-list>
< welcome-file> index.jsp</ welcome-file>
</ welcome-file-list>
</ web-app>
springmvc-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: mvc= " http://www.springframework.org/schema/mvc"
xmlns: context= " http://www.springframework.org/schema/context"
xsi: schemaLocation= "
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd" >
< context: component-scan base-package = " com.itcast.controller" />
< mvc: annotation-driven/>
< mvc: default-servlet-handler/>
< mvc: interceptors>
< mvc: interceptor>
< mvc: mapping path = " /*" />
< bean class = " com.itcast.interceptor.AuthorizedInterceptor" />
</ mvc: interceptor>
</ mvc: interceptors>
< bean id = " viewResolver"
class = " org.springframework.web.servlet.view.InternalResourceViewResolver" >
< property name = " prefix" >
< value> /page/</ value>
</ property>
< property name = " suffix" >
< value> .jsp</ value>
</ property>
</ bean>
< bean id = " multipartResolver"
class = " org.springframework.web.multipart.commons.CommonsMultipartResolver" >
< property name = " maxUploadSize" >
< value> 10485760</ value>
</ property>
< property name = " defaultEncoding" >
< value> UTF-8</ value>
</ property>
</ bean>
</ beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
< beans xmlns = " http://www.springframework.org/schema/beans"
xmlns: mybatis= " http://mybatis.org/schema/mybatis-spring"
xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
xmlns: p= " http://www.springframework.org/schema/p"
xmlns: context= " http://www.springframework.org/schema/context"
xmlns: mvc= " http://www.springframework.org/schema/mvc"
xmlns: tx= " http://www.springframework.org/schema/tx"
xsi: schemaLocation= " http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://mybatis.org/schema/mybatis-spring
http://mybatis.org/schema/mybatis-spring.xsd " >
< bean class = " org.mybatis.spring.mapper.MapperScannerConfigurer" >
< property name = " basePackage" value = " com.itcast.dao" />
</ bean>
< context: component-scan base-package = " com.itcast" >
< context: exclude-filter type = " annotation" expression = " org.springframework.stereotype.Controller" />
</ context: component-scan>
< context: property-override location = " classpath:db.properties" />
< bean id = " dataSource" class = " com.mchange.v2.c3p0.ComboPooledDataSource" />
< bean id = " sqlSessionFactory" class = " org.mybatis.spring.SqlSessionFactoryBean" >
< property name = " dataSource" ref = " dataSource" />
< property name = " mapperLocations" value = " classpath:com/itcast/dao/*.xml" />
< property name = " typeAliasesPackage" value = " com.itcast.domain" />
</ bean>
< bean id = " transactionManager"
class = " org.springframework.jdbc.datasource.DataSourceTransactionManager"
p: dataSource-ref= " dataSource" />
< tx: annotation-driven transaction-manager = " transactionManager" />
</ beans>
log4j.properties
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal
log4j.rootCategory=debug, CONSOLE, LOGFILE
# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=./log/itcast.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
db.properties
dataSource.driverClass=数据库驱动(MySQL8.0:com.mysql.cj.jdbc.Driver)
dataSource.jdbcUrl=jdbc:mysql://ip地址:端口号/数据库?serverTimezone=GMT%2B8
dataSource.user=用户名
dataSource.password=密码
dataSource.maxPoolSize=20
dataSource.maxIdleTime = 1000
dataSource.minPoolSize=6
dataSource.initialPoolSize=5