Spring-SpringMVC-Mybatis 整合相关 xml 配置文件
发布日期:2021-05-07 19:44:13 浏览次数:15 分类:精选文章

本文共 5101 字,大约阅读时间需要 17 分钟。

记录学习 Spring-SpringMVC-Mybatis 框架整合使用的 xml 配置文件,方便以后使用直接复制

分为 ,具体的其他配置,后续会继续更新。

案例:

  • 文章目录

一、不分模块的: ApplicationContext.xml

在这里插入图片描述

如果添加的是 druid 连接池则对应的连接池配置为:

如果使用 dp.properties 读取配置信息则为:

在这里插入图片描述

二、分模块:applicationContext.xml

在这里插入图片描述

oracle
true

三、dp.properties

注意配置文件必须是 x.xxx 的写法,如 jdbc.username,而不能写成 username

1. 选用c3p0 数据源

Mysql 配置连接:

jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/vuejdbc.username=rootjdbc.password=root

Oracle 配置连接:

jdbc.driver=oracle.jdbc.driver.OracleDriverjdbc.url=jdbc:oracle:thin:@192.168.245.128:1521:orcljdbc.username=ssmjdbc.password=root

对应的连接配置:

2. 选用 druid 数据源

jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/vuejdbc.username=rootjdbc.password=root

对应的连接配置:

三、搭建SpringMVC框架的web.xml

主要就是三大配置:监听器、控制器、编码器

org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath*:applicationContext.xml,classpath*:spring-security.xml
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
characterEncodingFilter
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*

四、不分模块:springMVC.xml

注意这里的视图解析器对应的目录:

只会在 WEB-INF/pages 下查找后缀为 .jsp 的页面

在这里插入图片描述
可以修改为其他目录;

在这里插入图片描述

五、分模块:springMVC.xml

六、spring-security.xml

需要注意

(1)
(2)是否使用SPEL,如果设置为TRUE,则access相应变为:
在这里插入图片描述
在这里插入图片描述
如果既想设置为false,又想使用 SPEL表达式,需要添加:

七、log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE.#log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatallog4j.rootCategory=info, 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.ConsoleAppenderlog4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayoutlog4j.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.FileAppenderlog4j.appender.LOGFILE.File=d:\axis.loglog4j.appender.LOGFILE.Append=truelog4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayoutlog4j.appender.LOGFILE.layout.ConversionPattern=%d{   ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
上一篇:一篇文章带你轻松搞定 SpringMVC ,Spring 和 Mybatis 的整合
下一篇:(Java 剑指 offer)二叉树的深度

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月26日 22时24分47秒