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)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...
随机推荐
- Ubuntu修改apt-get源
1.背景 服务器上安装了最新的Ubuntu Server 17.04,代号为zesty.使用apt-get命令安装软件时,有时候速度比较慢,有时候会失败.因此考虑用国内的镜像源更换下apt-get的默 ...
- nginx,gunicorn常用命令
nginx 启动: 在下载nginx的目录下直接输入nginx回车 停止: nginx -s stop 重启: nginx -s reload 查看当前运行进程: ps -ef | grep ngin ...
- C语言通过匿名管道实现反弹式CMDShell
#pragma comment(lib,"ws2_32.lib") #ifdef _MSC_VER #pragma comment( linker, "/subsyste ...
- Android逆向进阶(7)——揭开Hook的神秘面纱
本文作者:i春秋作家——HAI_ 0×00 前言 HAI_逆向使用手册(想尝试一下新的写法) 其他 Android逆向进阶 系列课程 <<<<<<< 人物说明 ...
- a 便签实现 下载
如果想通过纯前端技术实现文件下载,直接把a标签的href属性设置为文件路径即可,如下: <a href="https://cdn.shopify.com/s/files/1/1545/ ...
- iOS,Android,WP, .NET通用AES加密算法
这两天为移动App开发API,结果实现加密验证时碰到一大坑.这里不得不吐槽下又臭又硬的iOS,Windows Server无法解密出正确的结果,Android则可以,后来使用了通用的AES256加密算 ...
- python进程——生产者消费者
生产者消费者模型介绍 为什么要使用生产者消费者模型 生产者指的是生产数据的任务,消费者指的是处理数据的任务,在并发编程中,如果生产者处理速度很快,而消费者处理速度很慢,那么生产者就必须等待消费者处理完 ...
- dbvisulizer 存储过程
--/ CREATE PROCEDURE test () BEGIN DECLARE v CHAR(10) DEFAULT 'Hello';SELECT CONCAT(v, ', ', current ...
- 监督学习——决策树理论与实践(下):回归决策树(CART)
介绍 决策树分为分类决策树和回归决策树: 上一篇介绍了分类决策树以及Python实现分类决策树: 监督学习——决策树理论与实践(上):分类决策树 决策树是一种依托决策而建立起来的一种 ...
- Ruby:Open-uri和Net::HTTP的不同
OpenURI不仅可以用来发起http请求,也可以发起https和ftp请求