导入依赖坐标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. 机制设计原理与应用(三)Screening

    目录 3 Screening 3.1 为单个不可分割的项目定价 3.1.1 对\(\theta\)的假设 3.1.2 问题描述 3.1.3 特性 3.2 为无限可分的项目定价 3.2.1 对\(\th ...

  2. Linux安装ODBC连接SQLServer数据库

    操作系统:Centos7.2 1.下载ODBC安装包 unixODBC-2.3.9.tar.gz freetds-1.3.9.tar.gz 下载这两个压缩包的地址:ftp://ftp.freetds. ...

  3. Java中集合基础相关知识

    1.集合基础 1.1 集合概述 编程的时候如果需要存储多个数据使用长度固定的数据存储,适应不了元素个数变化的需求,这时候我们就需要用集合. 集合类的特点:提供了一种存储空间可变的存储模型,存储的数据容 ...

  4. XML_DTD_20200415

    <!-- xml的注释写法 --> 格式良好的xml语言必须具备的几个条件  1.必须有xml声明语句,声明版本号与编码字符集 2.必须有且仅有一个根元素 3.标签大小写敏感  4.属性值 ...

  5. [C#] Func及Action的快速Demo

    参考代码1: using System;using System.Collections.Generic;using System.Linq;namespace FuncActionDemo{    ...

  6. 深入理解css 笔记(7)

      前面讲了几种控制网页布局的方式,flex,gird 和 float.这下我们初略讲下 position.这个我日常中用到的已经挺多了.定位和其他控制文档流的行为不同.它将元素彻底从文档流中移走,它 ...

  7. 简单的python格网算法算数据密集度demo

    # 格网算法计算数据集区域数据密集度 import time import random import numpy as np import pandas as pd # 模拟数据集 def crea ...

  8. win10 python + selenium 环境搭建

    一.安装python3 1.下载地址: https://www.python.org/downloads/windows/ 直接选择最新版,下拉 file列表中,选择win10版 64位  Windo ...

  9. xcodeproj Building for iOS, but the linked and embedded framework ‘xxx.framework’ was built for iOS + iOS Simulator.

    一.报错 报错内容大致如下 /xxxx/xxx.xcodeproj Building for iOS, but the linked and embedded framework 'xxx.frame ...

  10. node+appium安装

      node是什么: node全称Node.js,是一个基于Chrome V8引擎的JavaScript运行环境,一个让JavaScript 运行在服务端的开发平台:它让JavaScript成为与PH ...