导入依赖坐标pom.xml

 <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.10.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.10.RELEASE</version>
</dependency> <dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.10.RELEASE</version>
</dependency> <dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>

config包

整合Spring配置

  • SpringConfig
@Configuration
@ComponentScan("com.cmq.service")
@Import({JdbcConfig.class,MybatisConfig.class})
@PropertySource("jdbc.properties")
public class SpringConfig {
}
  • jdbc.properties
jdbc.driver:com.mysql.jdbc.Driver
jdbc.url:jdbc:mysql://localhost:3306/db1
jdbc.username:root
jdbc.password:9999
  • jdbcConfig
public class JdbcConfig {
@Value("${jdbc.driver}")
private String driver;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
@Value("jdbc.password")
private String password; @Bean
public DataSource dataSource(){
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
}
  • MybatisConfig
public class MybatisConfig {
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(dataSource);
factoryBean.setTypeAliasesPackage("com.cmq.model");
return factoryBean;
} @Bean public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer msc = new MapperScannerConfigurer();
msc.setBasePackage("com.cmq.mapper");
return msc;
} }

SpringMVC整合配置

  • SpringMvcConfig
@Configuration
@EnableWebMvc
public class SpringMvcConfig {
}
  • ServletContainersInitConfig
public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class};
} @Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{SpringMvcConfig.class};
} @Override
protected String[] getServletMappings() {
return new String[]{"/"};
} // 处理中文乱码问题
@Override
protected Filter[] getServletFilters(){
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
return new Filter[]{filter};
} }

SSM整合的所有配置(配置类)的更多相关文章

  1. ssm整合(基于xml配置方式)

    本文是基于xml配置的方式来整合SpringMVC.Spring和Mybatis(基于注解的方式会再写一篇文章),步骤如下: (1)首先自然是依赖包的配置文件 pom.xml <project ...

  2. 基于IDEA实现SSM整合框架的搭建配置流程

    1.创建数据库表,以员工信息表为例子: DROP TABLE IF EXISTS `em_info`; CREATE TABLE `em_info` ( `em_id` INT(50) NOT NUL ...

  3. 基于Maven的SSM整合的web工程

    此文章主要有以下几个知识点: 一.如何创建 Maven的Web 工程 二.整合SSM(Spring,SpringMvc,Mybatis),包括所有的配置文件 三.用 mybatis 逆向工程生成对应的 ...

  4. SSM整合配置

    SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis) 使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...

  5. SSM 整合配置

    目录 1. Maven : pox.xml 2. Web container : web.xml 3. Spring context : dbconfig.properties + applicati ...

  6. ssm整合的spring.xml文件配置(applicationContext.xml)

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  7. ssm框架使用详解&配置两个数据源

    学习ssm框架已经快一年了,今天把这个框架总结一下. SSM 就是指 spring.SpringMVC和Mybatis.先说一下基本概念(百度上搜的) 1.基本概念 1.1.Spring Spring ...

  8. 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)

    http://blog.csdn.net/a67474506/article/details/61640548 Dubbo是什么东西我这里就不详细介绍了,自己可以去谷歌 SpringBoot整合Dub ...

  9. SpringBoot整合log4j2进行日志配置及防坑指南

    写在前面 最近项目经理要求将原先项目中的日志配置logBack,修改为log4j2,据说是log4j2性能更优于logback,具体快多少,网上有说快10多倍,看来还是很快的,于是新的一波挑战又开始了 ...

  10. 【Springboot】Springboot整合Jasypt,让配置信息安全最优雅方便的方式

    1 简介 在上一篇文章中,介绍了Jasypt及其用法,具体细节可以查看[Java库]如何使用优秀的加密库Jasypt来保护你的敏感信息?.如此利器,用之得当,那将事半功倍.本文将介绍Springboo ...

随机推荐

  1. cobbler安装CentOS-8系统

    cobbler安装CentOS-8系统 cobbler 1. cobbler简介 2. cobbler服务端部署 3. 客户端安装 4. 定制安装 1. cobbler简介 Cobbler是一个Lin ...

  2. P1413 坚果保龄球

    P1413 坚果保龄球 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 大家可以发现这里的坚果其实是火爆辣椒2333,那么我们要尽量多消灭僵尸,就需要在僵尸位于1列时在放置(ans+ ...

  3. P1296 奶牛的耳语

    P1296 奶牛的耳语 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 本题核心思路: 1.读入后要排序以达到剪枝的目的 2.模拟,遇到不能再交流就转入下一头牛,否则计数器加一 3. ...

  4. Springboot项目记录1配置环境

    一.电脑商城项目: 项目功能:登录,注册,热销商品,用户管理(密码,个人信息,头像,收货地址).购物车(展示.增加.删除).订单模块. 二.开发顺序: 注册.登录.用户管理.购物车.商品.订单模块 三 ...

  5. java 操作 zookeeper

    pom.xml<dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</a ...

  6. redis 配置哨兵模式时出现的问题(redis 版本 6.2.5)

    今天准备搭建一个 redis 集群(redis 版本 6.2.5),在这之前要先配置好哨兵模式. 但是在配置哨兵模式时出现了问题.之前没有搭建集群时(一主两从,三台虚拟机)可以顺利配置好,而搭建集群时 ...

  7. 在uni-app中调用高德地图去导航

    1.判断一下是不是在微信环境 2.微信环境调用微信自带的地图导航 3.h5环境跳转去高德地图 guide() { let self = this; console.log("self.lat ...

  8. Web_ServletContext主要方法

    ServletContext:联系上下文,一个项目通用一个context,作用域:整个项目 用法:Servlet里面直接应用,tomcat帮我们自动创建. 获取ServletContext:getSe ...

  9. dbeaver,执行SQL时,空行导致SQL执行报错" ERROR: syntax error at or near "case"Position: 1"

    dbeaver,执行SQL时,空行导致SQL执行报错" ERROR: syntax error at or near "case"Position: 1" 解决 ...

  10. Crypto入门 (五)混合编码

    前言: 这次得题目从本质上说没有什么难点,是多次利用base64和16进制编码,层层解开就好,通过这题得代码编写能很好得锻炼python代码能力,一起加油,尝试着自己写写看看把. 混合编码: 题目:J ...