SSM整合的配置文件
一、spring-web.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: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/context
- http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
- <!-- 1.开启SpringMVC注解模式 -->
- <!--
- 简化配置:
- 1)自动注册DefaultAnnotationHandlerMapping、AnnotationMethodHandlerAdapter
- 2)提供一系列的:数据绑定、数字和日期的format(@NumberFormat、@DateTimeFormat)、xml、json默认读写支持
- -->
- <mvc:annotation-driven>
- <mvc:message-converters register-defaults="true">
- <!-- 配置Fastjson支持 -->
- <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" id="fastJsonHttpMessageConverter">
- <property name="supportedMediaTypes">
- <list>
- <value>text/html;charset=UTF-8</value>
- <value>application/json</value>
- </list>
- </property>
- <property name="features">
- <list>
- <value>WriteMapNullValue</value>
- <value>QuoteFieldNames</value>
- </list>
- </property>
- </bean>
- </mvc:message-converters>
- </mvc:annotation-driven>
- <!-- 2.静态资源默认servlet配置 -->
- <!--
- 1)加入对静态资源的处理的支持(js、gif、png)
- 2)允许使用“/”做整体映射
- -->
- <mvc:default-servlet-handler/>
- <!-- 3.配置jsp的视图解析器 -->
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
- <property name="prefix" value="/WEB-INF/jsp/"></property>
- <property name="suffix" value=".jsp"></property>
- </bean>
- <!-- 4.扫描web相关的包 -->
- <context:component-scan base-package="com.demo.controller"/>
- <!-- 5.文件上传 -->
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
- <property name="defaultEncoding" value="utf-8"></property>
- <property name="maxUploadSize" value="32505856"></property>
- <property name="maxInMemorySize" value="4096"></property>
- </bean>
- <!-- 6.拦截器 -->
- <bean id="demoInterceptor" class="com.aidilude.auction.interceptor.DemoInterceptor"/>
- <mvc:interceptors>
- <mvc:interceptor>
- <!-- 对所有的请求拦截使用/** ,对某个模块下的请求拦截使用:/myPath/* -->
- <mvc:mapping path="/**" />
- <ref bean="demoInterceptor" />
- </mvc:interceptor>
- </mvc:interceptors>
- </beans>
二、spring-service.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:context="http://www.springframework.org/schema/context"
- 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-4.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <!-- 1.配置扫描service包下的所有使用注解的类 -->
- <context:component-scan base-package="com.demo.service"></context:component-scan>
- <!-- 2.配置事务管理器 -->
- <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"></property>
- </bean>
- <!-- 3.配置使用注解管理事务 -->
- <tx:annotation-driven transaction-manager="txManager"/>
- </beans>
三、spring-dao.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:context="http://www.springframework.org/schema/context"
- 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-4.0.xsd">
- <!-- 1.引入db.properties -->
- <context:property-placeholder location="classpath:jdbc.properties"/>
- <!-- 2.配置数据源 -->
- <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
- init-method="init" destroy-method="close">
- <!-- 一、基本项: -->
- <property name="url" value="${jdbc.url}" />
- <property name="username" value="${jdbc.username}" />
- <property name="password" value="${jdbc.password}" />
- <!-- 二、连接数量配置项: -->
- <!-- 2.1、初始化连接数
- 默认值:0
- -->
- <property name="initialSize" value="100" />
- <!-- 2.2、最大使用连接数
- 默认值:8
- -->
- <property name="maxActive" value="500" />
- <!-- 2.3、最小空闲连接数 -->
- <property name="minIdle" value="100" />
- <!-- 三、连接测试项: -->
- <!-- 3.1、获取连接的最大等待时间(毫秒) -->
- <property name="maxWait" value="10000" />
- <!-- 3.2、用来检测连接是否有效的sql,select 1:返回1 -->
- <property name="validationQuery" value="select 1" />
- <!-- 3.3、申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
- 默认值:true
- -->
- <property name="testOnBorrow" value="true" />
- <!-- 3.4、归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
- 默认值:false
- -->
- <property name="testOnReturn" value="false" />
- <!-- 3.5、建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
- 默认值:false
- -->
- <property name="testWhileIdle" value="true" />
- <!-- 四、Destory线程配置项: -->
- <!-- 4.1、Destory线程执行检测的时间间隔,检测需要关闭的空闲连接(毫秒) -->
- <property name="timeBetweenEvictionRunsMillis" value="60000" />
- <!-- 4.2、Destory线程如果检测到当前连接的最后活跃时间和当前时间的差值大于minEvictableIdleTimeMillis,则关闭当前连接(毫秒) -->
- <property name="minEvictableIdleTimeMillis" value="300000" />
- <!-- 五、remove线程项: -->
- <!-- 5.1、对于存活时间超过removeAbandonedTimeout的连接强制关闭 -->
- <property name="removeAbandoned" value="true" />
- <!-- 5.2、单位:秒 -->
- <property name="removeAbandonedTimeout" value="1800" />
- <!-- 5.3、关闭abanded连接时输出错误日志
- 默认值:false
- -->
- <property name="logAbandoned" value="true" />
- <!-- 六、监控项: -->
- <!-- 6.1、监控数据库 -->
- <property name="filters" value="mergeStat" />
- <!-- 七、选配项: -->
- <!-- 7.1、是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭
- 默认值:false
- <property name="poolPreparedStatements" value="true" />
- -->
- <!-- 7.2、每个连接上PSCache的大小 ,要配置必须大于0,当大于0了poolPreparedStatements自动触发为true
- 在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
- 默认值:-1
- <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
- -->
- </bean>
- <!-- 3.配置SqlSessionFactory(SqlSessionFactoryBean) -->
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <!-- 注入数据源 -->
- <property name="dataSource" ref="dataSource"></property>
- <!-- 引入mybatis全局配置文件 -->
- <property name="configLocation" value="classpath:mybatis-config.xml"></property>
- <!-- 扫描mapper映射文件 -->
- <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
- <!-- 扫描entity包,使用别名 -->
- <!-- 当定义了别名之后,就可以在入参或结果集中直接写类名(首字母大小写都可)了,而不用写全限定名 -->
- <property name="typeAliasesPackage" value=""></property>
- </bean>
- <!-- 4.扫描dao接口(MapperScannerConfigurer) -->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <!-- 注入sqlSessionFactory(注意使用value引入) -->
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
- <!-- 配置dao接口位置 -->
- <property name="basePackage" value=""></property>
- </bean>
- </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 -->
- <!-- select name as label from table -->
- <setting name="useColumnLabel" value="true"/>
- <!-- 开启驼峰命名转换:Table(create_time) -> Entity(createTime) -->
- <setting name="mapUnderscoreToCamelCase" value="true"/>
- <!-- 将延迟加载设置为true -->
- <setting name="lazyLoadingEnabled" value="true"/>
- <!-- 将积极加载设置为false -->
- <setting name="aggressiveLazyLoading" value="false"/>
- <!-- 二级缓存的总开关 -->
- <!-- 还需要在指定的mapper映射文件中开启独立的开关 -->
- <setting name="cacheEnabled" value="false"/>
- </settings>
- </configuration>
五、mapper.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <!-- mapper接口的全限定名 -->
- <mapper namespace="">
- <!-- 当前mapper开启二级缓存,默认使用PerpetualCache,可整合redis分布式缓存等 -->
- <!-- 当开启二级缓存,别忘了将对象序列化(实现Serializable) -->
- <!-- 查看日志中的缓存命中可以验证缓存是否成功开启 -->
- <!--
- <cache/>
- -->
- <!-- sql片段 -->
- <sql id="">
- <if test="">
- </if>
- <if test="">
- and id in
- <foreach collection="" item="" open="(" close=")" separator=",">
- </foreach>
- </if>
- </sql>
- <select id="" parameterType="" resultType="">
- <!-- <where>会去掉第一个条件的and,如果没有条件,那么去掉where -->
- <where>
- <!-- 引入代码片段 -->
- <include refid=""></include>
- </where>
- </select>
- <!-- 声明结果映射,用于需要将列别名映射为po类的属性名 -->
- <resultMap type="" id="">
- <id column="" property=""/>
- <result column="" property=""/>
- <!-- association标签用于映射引用数据类型 -->
- <!-- property:指定属性名,javaType:指定类型(全路径) -->
- <association property="" javaType="">
- <id column="" property=""/>
- <result column="" property=""/>
- </association>
- <!-- collection标签用于映射集合数据类型 -->
- <!-- ofType:指定类型(全路径) -->
- <collection property="" ofType="">
- <id column="" property=""/>
- <result column="" property=""/>
- </collection>
- </resultMap>
- <select id="" parameterType="" resultMap="">
- </select>
- </mapper>
SSM整合的配置文件的更多相关文章
- ssm整合各配置文件
ssm整合 1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns ...
- 基于Maven的SSM整合的web工程
此文章主要有以下几个知识点: 一.如何创建 Maven的Web 工程 二.整合SSM(Spring,SpringMvc,Mybatis),包括所有的配置文件 三.用 mybatis 逆向工程生成对应的 ...
- 零基础学习java------39---------json格式交互,Restful(不懂),静态资源映射,SSM整合(ssm整合思想,application.xml文件详解(声明式事务管理),)
一. json格式交互(知道) 1 . 回顾ajax基本语法 $.ajax({ url:"", // 请求的后台路径 data:{"":"" ...
- 整合ssm框架之配置文件
原文:https://blog.csdn.net/zwyanqing/article/details/53039591 ssm整合 一.applicationContext.xml 1.配置数据源 & ...
- 如何配置-整合ssm框架之配置文件
ssm整合 一.applicationContext.xml 1.配置数据源 <bean id="dataSource" class="org.springfram ...
- SSM框架的配置整合(包含配置文件代码)
由于SSM框架学习都要去网上或者以前的项目拷贝相同的代码,所以我在此把自己用到的配置文件全放在这里,帮助自己,帮助别人 首先开始前导入依赖和处理静态资源导出问题 <dependencies> ...
- SSM整合-配置文件
使用工具:maven.idea.jdk8.mysql.tomcat9.0 初学ssm框架,配置文件的配置目录: 其中genera ...
- Maven + 最新SSM整合
. 1. 开发环境搭建 参考博文:Eclipse4.6(Neon) + Tomcat8 + MAVEN3.3.9 + SVN项目完整环境搭建 2. Maven Web项目创建 2.1. 2.2. 2. ...
- SSM整合配置
SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis) 使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...
随机推荐
- MariaDB 库的基本操作(2)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...
- Swift5 语言参考(三) 类型
在Swift中,有两种类型:命名类型和复合类型.一个名为类型是当它的定义可以给出一个特定名称的类型.命名类型包括类,结构,枚举和协议.例如,名为的用户定义类的实例MyClass具有该类型MyClass ...
- 设计模式《JAVA与模式》之调停者模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述调停者(Mediator)模式的: 调停者模式是对象的行为模式.调停者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显引用.从 ...
- EF 通过修改模版 更改生成实体名称
直接修改T4 模版中对应关系就可以了,我这里是去掉了表中的“_”
- POJ 2545
#include<iostream> #include<stdio.h> #include<iomanip> #define MAXN 100000 using n ...
- FineBI学习系列之FineBI的ETL处理(图文详解)
不多说,直接上干货! 这是来自FineBI官网提供的帮助文档 http://help.finebi.com/http://help.finebi.com/doc-view-48.html 目录: 1. ...
- C++学习知识点
所谓的学习,知识只是一部分,理解知识是如何被抽象和提炼的过程,才是更重要的 1.c++代码里面的\(反斜杠) C语言的宏要求只能在同一行,是不能跨行的.这里的反斜杠就是告诉编译器,我这里虽然换行了,但 ...
- PHP设计模式:观察者模式
示例代码详见https://github.com/52fhy/design_patterns 观察者模式 观察者模式(Observer)是对象的行为模式,又叫发布-订阅(Publish/Subscri ...
- Shell脚本 | 一键获取安卓应用活动名
上篇文章提到,启动时间的计算需要用到应用启动页的活动名(Activity_Name). 如何获取活动名呢?通常有如下几种方式: 1.询问 Dev 同事 2.adb logcat ActivityMan ...
- Linux之SElinux安全上下文件(1)
SELinux:Secure Enhanced Linux,是美国国家安全局(NSA=The National Security Agency)和SCC(Secure Computing Courpo ...