Spring Web MVC 简单框架的搭建
按:记录一下初学的 spring web mvc 简单框架的搭建过程。
0. 项目总体结构
项目由maven工具管理
demo-system |-- demo-system-module-mvc | |-- src | | |-- main | | | |-- java | | | |-- resources | | | | |-- sqlMapper | | | | | |-- *.xml | |-- pom.xml |-- demo-system-module-web | |-- src | | |-- main | | | |-- java | | | |-- logs | | | |-- resources | | | | |-- config | | | | | |-- jdbcConfig.properties | | | | |-- applicationContext.xml | | | | |-- applicationContext-db.xml | | | |-- webapp | | | | |-- WEB-INF | | | | | |-- web.xml | |-- pom.xml |-- pom.xml
涉及到的技术主要包括:spring web mvc; mybatis; druid(Oracle); logback。JDK版本为1.8.0_191。
- 项目配置的POM文件
1.1demo-system.pom.xml
org.springframework
spring-webmvc
5.3.8
org.springframework
spring-jdbc
5.3.8
com.alibaba
druid
1.2.4
com.oracle
ojdbc6
11.2.0.4.0
org.mybatis
mybatis
3.5.6
org.mybatis
mybatis-spring
2.0.6
ch.qos.logback
logback-classic
1.2.3
1.2 demo-system-module-web.pom.xml
com.fasterxml.jackson.core
jackson-databind
2.12.1
- web配置文件
demo-system-module-web.src.main.webapp.WEB-INF.web.xml
springMvcDispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:/applicationContext*.xml
1
springMvcDispatcher
*.action
.do
druidStatView
com.alibaba.druid.support.http.StatViewServlet
loginUsername
admin
loginPassword
admin
druidStatView
/druid/*
- jdbc配置文件
demo-system-module-web.src.main.resources.config.jdbcConfig.properties
jdbc.url=jdbc:oracle:thin:@192.168.0.1:3306:root
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.username=root
jdbc.password=root
# 初始化时建立物理连接的个数
jdbc.initialSize=1
# 最小连接数
jdbc.minIdle=1
# 允许最大连接数,超过后在队列中等候,最大的等待请求数由 maximun-new-connections决定
jdbc.maxActive=60
# 最大等待时间
jdbc.maxWait=5000
# SQL执行超过一定时间则记录为慢SQL
jdbc.dialect=oracle
jdbc.slowSqlMillis=3000
# 慢SQL统计日志输出
jdbc.logSlowSwql=false
# 合并SQL统计
jdbc.mergeSql=false
# 检测需要关闭的空闲连接的间隔时间
jdbc.timeBetweenEvictionRunsMillis=120000
- 数据库Druid配置
demo-system-module-web.src.main.resources.applicationContext-db.xml
- 根配置文件
demo-system-module-web.src.main.resources.applicationContext.xml
结语
这里只是记录了关键的具体配置,其余的内容可以轻松地通过其他网络文章获得,其中各个依赖的版本在顺利运行前不建议更改,有小概率会发生一些奇怪的错误。