SSM框架整合方案(Spring+SpringMVC+Mybatis)

2023-11-06

一、将application进行纵向切分,每一个配置文件只配置与之相关的Bean


  除此之外,项目中通常还有log4j.properties、SqlMapConfig.xml、db.properties文件

二、 各文件配置方案详解

(1)日志组件log4j的配置文件:log4j.properties

log4j.rootLogger=DEBUG,A1
log4j.logger.org.mybatis = DEBUG
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n

(2)Mybatis框架的配置文件:sqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
		PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
		"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<plugins>  
   	<!-- 分页插件 -->
    <plugin interceptor="com.github.pagehelper.PageHelper">  
        <property name="dialect" value="mysql"/>  
    </plugin>  
</plugins>  
</configuration>


(3)数据库连接源配置文件:db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456

(4)Dao层配置文件:applicationContext-dao.xml

配置内容:

a.数据库连接池

b.SqlSessionFactory

c.配置mapper文件的扫描器

详细配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

	<!-- 加载配置文件 -->
	<context:property-placeholder location="classpath:properties/*.properties"/>
	<!-- 数据库连接池 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		destroy-method="close">
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="maxActive" value="10" />
		<property name="minIdle" value="5" />
	</bean>
	<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 数据库连接池 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 加载mybatis的全局配置文件 -->
		<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
	</bean>
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.taotao.mapper" />
	</bean>
</beans>

(5)Service层配置文件:applicationContext-service.xml

配置内容:

a.配置一个包扫描器

详细配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

	<!-- 包扫描器,扫描带@Service注解的类 -->
	<context:component-scan base-package="com.taotao.service"></context:component-scan>
	
</beans>

(6)Transaction配置文件:applicationContext-trans.xml

配置内容:

a.配置一个事务管理器

b.配置tx

c.配置切面

详细配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
	<!-- 事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 数据源 -->
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 传播行为 -->
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
			<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
			<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<!-- 切面 -->
	<aop:config>
		<aop:advisor advice-ref="txAdvice"
			pointcut="execution(* com.taotao.service.*.*(..))" />
	</aop:config>
</beans>

(7)Web层配置文件:springmvc.xml
配置内容:

a.配置注解驱动

b.配置一个视图解析器

c.包扫描器

详细配置文件:

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    
    <!-- 配置包扫描器 -->    
    <context:component-scan base-package="com.taotao.controller"></context:component-scan>
    <!-- 配置注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 视图解析器 -->
    <bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
	<!-- 静态资源映射 -->
	<mvc:resources location="/js/" mapping="/js/**"/>
	<mvc:resources location="/css/" mapping="/css/**"/>
</beans>        

(8)部署描述符:web.xml

配置内容:

a.配置springmvc前端控制器

b.Spring容器初始化的listener

具体配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="taotao" version="2.5">
	<display-name>taotao-manager</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
	<!-- 初始化spring容器 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/applicationContext-*.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- 解决post乱码 -->
	<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>


	<!-- springmvc的前端控制器 -->
	<servlet>
		<servlet-name>taotao-manager</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>taotao-manager</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

三、总结

配置文件的拆分是根据项目的拆分进行的,这样每个配置文件只用负责对应的区域即可,很好的实现了模块化管理。


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SSM框架整合方案(Spring+SpringMVC+Mybatis) 的相关文章

  • boost静态链接库和c++/clr不兼容问题:未能加载文件或程序集,不是有效的Win32应用程序。

    项目上遇到的问题 c 编写的类使用托管c 包装成dll提供给c 项目使用 c 需要使用boost clr 项目目标平台都是win32 x86 开发环境win10 x64系统 vs2013 Net Framework 4 0 boost 1
  • MOSFET、IGBT的结构与工作原理详解

    来自百度百科 先学习一下MOSFET 图1是典型平面N沟道增强型NMOSFET的剖面图 它用一块P型硅半导体材料作衬底 在其面上扩散了两个N型区 再在上面覆盖一层二氧化硅 SiO2 绝缘层 最后在N区上方用腐蚀的方法做成两个孔 用金属化的方
  • web性能测试基本性能指标

    文章出处 https blog csdn net qiguiting article details 11584397 Web性能测试的部分概况一般来说 一个Web请求的处理包括以下步骤 1 客户发送请求 2 web server接受到请求
  • 从DEMO到完成项目过程的流程

    一 项目评审 认真看demo需求是关键 根据项目demo原型 将项目功能点细分 按每个功能点实现的大致期限 去估计整个项目的期限 一旦项目评估预期确定 需要严格按照预期来实现 决不能拖拉 二 项目实施中 项目实施中 尽量以实现demo功能为
  • @Profile使用及SpringBoot获取profile值

    之前开发用过 maven 的环境隔离 现在使用springboot的 Profile功能 发现spring体系真的大到我只是学习了皮毛 相比面试问的 IOC bean的作用域等 突然觉得很可笑 官方文档关于 Profile 的使用 http
  • 项目实用功能-全局loading动画

    1 为设么要使用全局loading 调用的每一个接口都要绑定一个loading真的很烦 2 实现这个需要考虑哪些要素 首先全局的loading需要一个调用任何接口都要执行的地方打开 那就肯定是axios的前置拦截函数了 loading有加载
  • xml转JavaBean

    在进行webservice通信的时候 需要解析xml为一个对象 由于个人也是第一次接触xml转对象 于是参考网上的例子写了一个工具类 所有jar包支持 fastjson dom4j public class XmlConverBeanUti
  • SSM框架整合方案(Spring+SpringMVC+Mybatis)

    一 将application进行纵向切分 每一个配置文件只配置与之相关的Bean 除此之外 项目中通常还有log4j properties SqlMapConfig xml db properties文件 二 各文件配置方案详解 1 日志组
  • Java随机生成8位字符串

    转载 http www aichengxu com java 6875596 htm 因业务需要 使用UUID生成32位的字符串有点长 这个生成8位的字符串方案可行 public static String chars new String
  • 国信证券笔试题总分120分

    国信证券笔试题总分120分 1 选择题60分 20题 单选 10 每题3分 多选 10 每题3分 2 业务题 每题4分总共20分 2 1 post get请求区别 后退按钮 刷新 无害 数据会被重新提交 浏览器应该告知用户数据会被重新提交
  • react+antd 修改主题色

    项目使用的时 react 框架 和 ant design ui组件库 antd 官网中对定制主体是这样说的 详见 https ant design docs react customize theme cn 官网说的是 antd 的样式使用
  • 苹果个人公司类型开发者账号申请(99美元)详解

    最近有用 记录一下 谈到苹果开发者账号 我们需要区分一下个人账号 公司账号和企业账号这三种 还有一种是教育账号 这个就不多说了 个人账号 个人申请用于开发苹果app所使用的账号 仅限于个人使用 申请比较容易 99 公司账号 以公司的名义申请
  • elementui表格自定义表头的两种方法

    表格自定义表头的方式 多选框表头换文字 请查看上篇博客 http t csdn cn 69De2 文字换按钮 render header render header方法详情 Table column Attributes 参数 说明 类型
  • 【项目经验】:项目中下拉框数据太多造成页面卡顿(二)

    一 项目需求 下拉框下拉列表数据是由后端返回的 而且他会变化 所以数据不是写死的而且数据量大 上一篇博客http t csdn cn sSNTa我们是用的数据懒加载的方式 这次我们使用远程搜索的方式解决这个问题 二 用到的组件方法介绍 fi
  • ssm框架中,mybatis的sql语句日志输出

    在ssm框架中 常用的日志输出为Log4j 但按照常规的配置 涉及mybatis那部分日志不能打印出来的 由于没有日志的输出 开发人员很难从控制台中迅速找出相应的sql语句 对调试和找错误带来了一定的困扰 针对这个问题 我们需要额外的配置以
  • 使用Idea创建一个JavaWeb的SSM(maven)项目~(史上最详细,傻瓜式教学,跟着我的做,不会你找我)

    今天讲的是如何用idea创建一个JavaWeb的Maven SSM项目并且实现简单的登陆功能 项目源码在最后 需要的可以自行下载 本文章过于详细过于面向小白 并且在讲解SSM项目的搭建过程中涉及到了小白们极有可能遇到的Idea的坑 文章比较
  • 软件工程的发展历程及展望

    软件工程发展至今 催生出了许多优秀的编程语言和编程思想 本文将带领大家一起了解软件工程经历的四个阶段 汇编语言表达业务逻辑 过程化语言表达业务逻辑 面向对象和模块化思想表达业务逻辑 服务化和组件化表达业务逻辑 最后谈一谈未来可能的发展方式
  • 滚动页面触发相应位置动画 ---react

    需要实现的效果 滚动到内容区域触发 第一段内容移动效果 第二段内容淡入 第三段内容缩放 实现思路 滚动过的距离 当前窗口的高度 gt 元素到顶部窗口的距离 gt 则触发动画 整体代码 import React useRef useEffec
  • MyBatis-Generator插入删除数据返回-2147482646

    在使用MyBatis Generator自动生成的代码进行删除数据时 deleteByPrimaryKey 方法 返回的int 值为 2147482646 正常的逻辑是成功删除返回 1 失败返回 0 未删除数据 特意去官网看了这个方法的说明
  • MyBatis-Plus主键生成策略

    主键生成策略 MyBatis Plus默认实现5种主键生成策略 分别是 AUTO 配合数据库设置自增主键 可以实现主键的自动增长 类型为nmber INPUT 由用户输入 NONE 不设置 等同于INPUT ASSIGN ID 只有当用户未

随机推荐

  • Python网络爬虫之数美滑块的加密及轨迹之动态js参数分析

    前言 数美滑块的加密及轨迹等应该是入门级别的吧 用他们的教程和话来说 就一个des 然后识别缺口位置可以用cv2或者ddddoc 轨迹 也可以随便模拟一个 这些简单的教程 在csdn已经有一大把可以搜到的 但是却很少人告诉你 它的js好像是
  • CMake 命令

    1 Usage cmake options
  • MAC安装渗透测试靶机

    1 mac 安装docker 直接到docker官网下载docker dmg 下载前先要注册docker 下载后直接安装就可以了 docker version 就能看见安装的版本 我的版本17 03 1 ce 2 下载docker镜像ima
  • 了解l电源纹波PSRR----转摘

    PSRR 就是 Power Supply Rejection Ratio 的缩写 中文含意为 电源纹波抑制比 也就是说 PSRR 表示把输入与电源视为两个独立的信号源时 所得到的两个电压增益的比值 基本计算公式为 PSRR 20log Ri
  • 【C语言】-- 整型数据的存储

    目录 1 数据类型的分类 2 基本类型 2 1 基本类型大小 2 2 整型家族 2 3 数据的存储形式 2 4 整形数据的存储方式 1 数据类型的分类 在C语言中有如下类型 2 基本类型 2 1 基本类型大小 一个变量的创建是要在内存中开辟
  • node の SQLite

    node操作SQLite 之前在做electron桌面制作番茄钟应用时曾经想过用数据库存储数据 一开始打算mongodb 但是发现不能实现无服务器 那么只能使用SQLite了 介绍 SQLite 是一个软件库 实现了自给自足的 无服务器的
  • android 前端常用布局文件升级总结(一)

    问题一 android support design widget CoordinatorLayout 报红 不显示页面 解决方法 把xml布局文件里面的 android support design widget CoordinatorL
  • SpringBoot + Prometheus + Grafana 打造可视化监控

    SpringBoot Prometheus Grafana 打造可视化监控 文章目录 SpringBoot Prometheus Grafana 打造可视化监控 常见的监控组件搭配 安装Prometheus 安装Grafana 搭建Spri
  • [正能量系列]失业的程序员(一)

    注 本文原型为作者的好友 全文不完全代表作者本人的意图 不小心 我失业了 原因是前几天和我的部门经理拍了桌子 我的组员去内蒙古出差 项目没有中标 年后 长得很像猪刚烈的部门经理发飙了 要辞退我的组员 我纳闷了 我的组员是技术支持 要退也应该
  • Proxmox VE虚拟化从入门到应用实战-服务器管理篇(网络配置2

    Proxmox VE虚拟化从入门到应用实战 服务器管理篇 网络配置2 一 Linux多网口绑定 多网口绑定 也称为网卡组或链路聚合 是一种将多个网卡绑定单个网络设备的技术 利用该技术可以实现某个或多个目标 例如提高网络链容错能力 增加网络通
  • 哈希算法总结

    目录 1 Hash是什么 它的作用 2 Hash算法有什么特点 2 1 Hash在管理数据结构中的应用 2 1 Hash在在密码学中的应用 3 Hash算法是如何实现的 4 Hash有哪些流行的算法 5 那么 何谓Hash算法的 碰撞 5
  • Markdown文件关机没保存,怎么恢复

    1 2 点开找到你想恢复的时间段的文件
  • JS date格式化

    Date prototype Format function fmt author meizz use strict jshint var o M this getMonth 1 月份 d this getDate 日 h this get
  • Qt Creator中,include路径包含过程(或如何找到对应的头文件)

    Qt Creator中 include路径包含过程 或如何找到对应的头文件 利用Qt Creator开发程序时 需要包含利用 include来添加头文件 大家都知道 include lt gt 用于包含标准库头文件 路径在安装软件的incl
  • centos7环境下mysql8的tar包的安装及配置

    内网环境下安装及配置 并将数据保存指向某个文件夹 因为博主这里的数据文件夹是有硬盘挂靠的 centos 7 aliyun CentOS 7 x86 64 DVD 1810 mysql mysql 8 0 17 linux glibc2 12
  • 【题解】闯关游戏

    题目描述 艾伦正在闯关 游戏有N个关卡 按照必须完成的顺序编号为1到N 每个关卡可以用两个参数来描述 prob i 和value i 这些参数的含义如下 每当艾伦尝试闯第i关时 他要么顺利通过 要么 挂掉 他完成该关卡的概率总是prob i
  • Red5应用开发(二)直播串流与录制

    环境 操作系统 win10 1803 Eclipse版本 4 7 3a Oxygen J2EE版本 Red5 Server版本 1 0 8 Release 环境搭建参考前一篇文章 Red5应用开发 一 开发环境搭建 后续不再涉及red5 f
  • 职场加班

    总是听到形形色色的职场加班过劳死的故事 甚至有人写了一篇文章 别让老板杀了你 职场果真那么恐怖吗 其实公司怎么想那是公司的事情 公司有权想着把你干掉 把你榨干 因为这样对于公司最有利 但是 问题在于我们自己怎么想呢 在我看来 在这个社会上混
  • python 泛型函数--singledispatch的使用

    functools singledispatch 将一个函数转变为单一分派的泛型函数 用 singledispatch装饰一个函数 将定义一个泛型函数 注意 我们创建的函数获得分派的依据是第一个参数的类型 from functools im
  • SSM框架整合方案(Spring+SpringMVC+Mybatis)

    一 将application进行纵向切分 每一个配置文件只配置与之相关的Bean 除此之外 项目中通常还有log4j properties SqlMapConfig xml db properties文件 二 各文件配置方案详解 1 日志组