SSM三大框架整合配置(Spring+SpringMVC+MyBatis)
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
- http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
- id="WebApp_ID" version="3.1">
- <!-- 定义Spring MVC的前端控制器 -->
- <servlet>
- <servlet-name>UserManage</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/config/UserManage-servlet.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <!-- 让Spring MVC的前端控制器拦截所有请求 -->
- <servlet-mapping>
- <servlet-name>UserManage</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!-- ================Spring配置开始================ -->
- <!-- 设置Spring容器加载配置文件的路径 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>WEB-INF/config/spring-config.xml</param-value>
- <!-- <param-value>classpath:/spring-*.xml</param-value> -->
- </context-param>
- <!-- 配置Spring监听器,可以在容器启动时,加载contextConfigLocation的context-param节点的配置文件 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- ================Spring配置结束================ -->
- <!-- 防止Spring内存溢出监听器 -->
- <listener>
- <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
- </listener>
- <!-- 指定首页 -->
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <!-- 配置SESSION超时,单位是分钟 -->
- <session-config>
- <session-timeout>10</session-timeout>
- </session-config>
- <!--如下此段编码设置必须在所有filter的前面,否则过滤器有可能不起作用。
- 设置编码方式为UTF-8,解决中文乱码问题。-->
- <filter>
- <filter-name>CharacterEncoding</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>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>CharacterEncoding</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
UserManage-servlet.xml
- <?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:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-4.2.xsd">
- <!-- spring可以自动去扫描base-pack下面的包或者子包下面的java文件,
- 如果扫描到有Spring的相关注解的类,则把这些类注册为Spring的bean -->
- <context:component-scan base-package="org.usermanage.controller"/>
- <!-- 配置处理映射器 -->
- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
- <!-- 配置处理器适配器-->
- <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
- <!-- 视图解析器 -->
- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <!--指定默认前缀,controller中直接写文件名即可-->
- <property name="prefix" value="/WEB-INF/content/jsp/"></property>
- </bean>
- <!--指定单独处理的资源,不经过DispatcherServlet-->
- <mvc:annotation-driven/>
- <!--所有以html结尾的请求全部到指定目录下查询-->
- <mvc:resources mapping="/*.html" location="WEB-INF/content/html/"></mvc:resources>
- <mvc:resources mapping="/*.js" location="WEB-INF/content/js/"></mvc:resources>
- <mvc:resources mapping="/*.css" location="WEB-INF/content/css/"></mvc:resources>
- <mvc:resources mapping="/login/*.css" location="WEB-INF/content/css/login/"></mvc:resources>
- </beans>
spring-config.xml
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
- <!-- 加载配置jdbc属性文件 -->
- <!--MapperScannerConigurer实际是在解析加载bean定义阶段的,这个时候要是设置sqlSessionFactory的话,
- PropertyPlaceholderConfigurer还没来得及替换定义中的变量,导致把表达式当作字符串复制了
- 修改如下:-->
- <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <list>
- <value>WEB-INF/config/jdbc.properties</value>
- <!--要是有多个配置文件,只需在这里继续添加即可 -->
- </list>
- </property>
- </bean>
- <!--配置c3p0连接池-->
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
- <!--注入属性-->
- <property name="driverClass" value="${driver}"></property>
- <property name="jdbcUrl" value="${url}"></property>
- <property name="user" value="${username}"></property>
- <property name="password" value="${password}"></property>
- <!-- c3p0连接池的私有属性 -->
- <property name="maxPoolSize" value="30"/>
- <property name="minPoolSize" value="10"/>
- <!-- 关闭连接后不自动commit -->
- <property name="autoCommitOnClose" value="false"/>
- <!-- 获取连接超时时间 -->
- <property name="checkoutTimeout" value="10000"/>
- <!-- 当获取连接失败重试次数 -->
- <property name="acquireRetryAttempts" value="2"/>
- </bean>
- <!--SqlSessionFactoryBean配置-->
- <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <!--Mybatis配置文件,非必须-->
- <property name="configLocation" value="WEB-INF/config/mybatis-config.xml"/>
- <property name="dataSource" ref="dataSource"/>
- <!--扫描mapper.xml文件的位置-->
- <property name="mapperLocations" value="classpath:org/usermanage/mapper/*.xml"/>
- </bean>
- <!-- 配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <!-- 注入sqlSessionFactory,单个dataSource时可省略 -->
- <!--<property name="sqlSessionFactoryBeanName" value="sqlsessionFactory"/>-->
- <!-- 给出需要扫描Dao接口包 -->
- <property name="basePackage" value="org.usermanage.mapper"/>
- </bean>
- <!--扫描所有使用注解的类型,使用Annotation自动注册Bean-->
- <context:component-scan base-package="org.usermanage"/>
- <!-- 事务配置 -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- </bean>
- <!-- 使用annotation注解方式配置事务 -->
- <!--<tx:annotation-driven transaction-manager="transactionManager"/>-->
- </beans>
mybatis-config.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>
- <settings>
- <!-- 使用jdbc的getGeneratedKeys获取数据库自增主键值 -->
- <setting name="useGeneratedKeys" value="true"/>
- <!-- 使用列别名替换列名 默认:true -->
- <setting name="useColumnLabel" value="true"/>
- <!-- 开启驼峰命名转换:Table{create_time} -> Entity{createTime} -->
- <setting name="mapUnderscoreToCamelCase" value="true"/>
- </settings>
- <!--从外部配置文件导入jdbc信息-->
- <!--<properties resource="config/jdbc.properties"></properties>-->
- <!--<environments default="development">-->
- <!--<environment id="development">-->
- <!--<transactionManager type="JDBC"/>-->
- <!--<dataSource type="POOLED">-->
- <!--<property name="driver" value="${driver}"/>-->
- <!--<property name="url" value="${url}"/>-->
- <!--<property name="username" value="${username}"/>-->
- <!--<property name="password" value="${password}"/>-->
- <!--</dataSource>-->
- <!--</environment>-->
- <!--</environments>-->
- <!--指定映射资源文件-->
- <!--<mappers>-->
- <!--<mapper resource="classpath:org/usermanage/mapper/UserMapper.xml"/>-->
- <!--</mappers>-->
- </configuration>
jdbc.properties
- # jdbc连接信息
- driver=com.mysql.jdbc.Driver
- #url=jdbc:mysql://192.168.184.130:3306/gxrdb
- url=jdbc:mysql://10.15.1.200:3306/gxrdb?useUnicode=true&characterEncoding=utf8
- username=root
- password=root
SSM三大框架整合配置(Spring+SpringMVC+MyBatis)的更多相关文章
- SSM三大框架整合(Spring+SpringMVC+MyBatis)
一. 导包 18个必须的包 二.配置Spring MVC的web文件 <?xml version="1.0" encoding="UTF-8"?> ...
- 手动配置三大框架整合:Spring+Struts2+mybatis
如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...
- SSM框架整合(Spring+SpringMVC+MyBatis+Oracle)
1.开发环境搭建以及创建Maven Web项目 参看之前的博文[确保maven web项目不报错]:http://www.cnblogs.com/cainiaomahua/p/6306476.html ...
- SSM框架的配置Spring+Springmvc +Mybatis
ssm框架是由spring mvc +spring+mybatis组成 快速阅读 通过spring的配置文件spring.xml,在servlet中指定spring mvc的配置文件spring-mv ...
- SSM框架整合(Spring + SpringMVC + MyBatis)
搭建环境 使用Spring(业务层)整合其他的框架SpringMVC(表现层)和MyBatis(持久层) Spring框架 创建数据库表 CREATE DATABASE ssm; USE ssm; C ...
- 04_SSM框架整合(Spring+SpringMVC+MyBatis)
[SSM的系统架构] [整合概述] 第一步: MyBatis和Spring整合,通过Spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在Spring中进行注册. 第二 ...
- SSM框架整合(注解)-Spring+SpringMVC+MyBatis+MySql
准备工作: 下载整合所需的jar包 点击此处下载 使用MyBatis Generator生成dao接口.映射文件和实体类 如何生成 搭建过程: 先来看一下项目的 目录结构 1.配置dispatcher ...
- SSM简明教程:简单的十步教你搭建人生第一个SSM框架[ SSM框架整合教程(Spring+SpringMVC+MyBatis) ]
SSM_BookSystem SSM框架基础 SSM_BookSystem ---> Hello CRUD 说明:本项目目前包含基础的CRUD 日期:2017-05-01 22:25:37 作者 ...
- SSM三大框架整合配置详解
首先,导入框架所需要的全部jar包(此处省略...........) 第一步:先从mybatis框架开始 我们只需要在mybatis的核心配置文件sqlConfigXml里写上这么一段话,代表的是给p ...
随机推荐
- 最小生成树(图论)--3366lg【模版】
题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N<=5000,M<= ...
- CTS 如何处理 gating clock 和 generated clock
1. CTS 时会将 ICG cell 作为 implicit nostop pin 处理,直接穿透,以 ICG cell 后面的 sink 点作为真正的 sink 来长 tree 2. CTS 时会 ...
- Centos6.8配置HTTPS
HTTPS服务http+openssl 环境要求:CA证书: 192.168.1.103网站服务器: 192.168.1.104客户端: 192.168.1.107 (linux图形化界面) 内核:( ...
- @synchronized深入理解
@synchronized是线程同步锁,易用.可读性高. @synchronized(self) { 临界区 } 利用如下命令将其重写 clang -rewrite-objc file 得到C++实 ...
- Codeforces Hello 2019
Hello 2019 手速场qwq 反正EGH太神仙了啊.jpg 考试的时候不会啊.jpg A 暴力.jpg #include <cstdio> #include <algorith ...
- CF908D New Year and Arbitrary Arrangement 期望、DP
题目传送门 题意:给出正整数$pa,pb,k$,最开始你有一个空串,每一次你有$\frac{pa}{pa + pb}$的概率向串最后放一个$a$,有$\frac{pb}{pa + pb}$的概率向串最 ...
- wpf项目打开多个窗体在任务栏只有一个任务
原文:wpf项目打开多个窗体在任务栏只有一个任务 如果在wpf里,在一个父窗体上打开子窗体,只在任务栏显示一个任务,不是qq聊天窗口俩人聊天人显示俩给那样,只能显示 一个 private void B ...
- Luogu P1306 斐波那契公约数
这道题其实是真的数学巨佬才撸的出来的题目了 但如果只知道结论但是不知道推导过程的我感觉证明无望 首先这道题肯定不能直接搞,而且题目明确说明了一些方法的问题 所以就暗示我们直接上矩阵了啦 但是如果直接搞 ...
- CQOI2018简要题解
CQOI2018简要题解 D1T1 破解 D-H 协议 题意 Diffie-Hellman 密钥交换协议是一种简单有效的密钥交换方法.它可以让通讯双方在没有事先约定密钥(密码)的情况下,通过不安全的信 ...
- 浅谈nornalize.css(含源码)
Normalize.css是一种CSS reset的替代方案.经过@necolas和@jon_neal花了几百个小时来努力研究不同浏览器的默认样式的差异,这个项目终于变成了现在这样. 我们创造norm ...