Spring PropertyPlaceholderConfigurer数据库配置
pom.xml
中添加依赖
<!-- mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.20</version>
</dependency>
属性配置文件:system-config.properties
################################################
# DataSource Config
jdbc.url=jdbc\:mysql\://127.0.0.1:3306/quartz?useUnicode\=true&characterEncoding\=utf8&autoReconnect\=true&useSSL\=false&zeroDateTimeBehavior\=convertToNull
jdbc.username=root
jdbc.publicKey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALIT9sFn8U+Hoo80Q+Hepwc0ZN6HBiyAW4SiLCXLhNNjxB45mtRamABoB0O9dEsziT/gwtuXMuC2bWePdCvEb1ECAwEAAQ==
jdbc.password=fCHxOiDBDsWY/BJLg05fbNGvQmDRPZJufcvyqCqml+zwmB4Gw/Bn7lzy8w117CQ1jEBFpj0ERgQsCBJD0ROfJw==
applicationContext.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.xsd">
<!-- 只需要加载service、dao即可,不需要加载controller -->
<context:component-scan base-package="com.quartz">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>
<!-- 占位符 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:system-config.properties</value>
</list>
</property>
</bean>
<!-- 防SQL注入过滤器 -->
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql" />
</bean>
<!-- 监控信息过滤器 -->
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<!-- slowSqlMillis用来配置SQL慢的标准,执行时间超过slowSqlMillis的就是慢。 -->
<property name="slowSqlMillis" value="10000" />
<property name="logSlowSql" value="true" />
<property name="mergeSql" value="true" />
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<!-- 密码加密 -->
<property name="filters" value="config" />
<property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${jdbc.publicKey}" />
<property name="password" value="${jdbc.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="5" />
<property name="minIdle" value="5" />
<property name="maxActive" value="30" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="false" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
<!-- 超过时间限制是否回收 -->
<property name="removeAbandoned" value="true" />
<!-- 超时时间;单位为秒。180秒=3分钟 -->
<property name="removeAbandonedTimeout" value="180" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
<property name="proxyFilters">
<list>
<!-- 监控信息过滤器 -->
<ref bean="stat-filter" />
<!-- 防注入的话从前台传排序字段排序不好用 -->
<ref bean="wall-filter" />
</list>
</property>
</bean>
</beans>
Spring PropertyPlaceholderConfigurer数据库配置的更多相关文章
- spring读取数据库的配置信息(url、username、password)时的<bean>PropertyPlaceholderConfigurer的用法
用法1: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...
- Spring 数据库配置用户名和密码加密
单个数据库配置 : 一般spring容器启动时,通过PropertyPlaceholderConfigurer类读取jdbc.properties文件里的数据库配置信息.通过这个原理,我们把加密后的数 ...
- spring+mybatis的多源数据库配置实战
前言: 关于spring+mybatis的多源数据库配置, 其实是个老生常谈的事情. 网上的方案出奇的一致, 都是借助AbstractRoutingDataSource进行动态数据源的切换. 这边再无 ...
- spring BasicDataSource 数据源配置 sqlserver数据库 oracle数据库 mysql数据jdbc配置
spring BasicDataSource 数据源配置 sqlserver数据库 oracle数据库 mysql数据jdbc配置 jdbc.properties 文件信息如下: ---------- ...
- Spring+MyBatis双数据库配置
Spring+MyBatis双数据库配置 近期项目中遇到要调用其它数据库的情况.本来仅仅使用一个MySQL数据库.但随着项目内容越来越多,逻辑越来越复杂. 原来一个数据库已经不够用了,须要分库分表.所 ...
- 【Spring】Spring的数据库开发 - 1、Spring JDBC的配置和Spring JdbcTemplate的解析
Spring JDBC 文章目录 Spring JDBC Spring JdbcTemplate的解析 Spring JDBC的配置 简单记录-Java EE企业级应用开发教程(Spring+Spri ...
- spring读取加密配置信息
描述&背景Spring框架配置数据库等连接等属性时,都是交由 PopertyPlaceholderConfigurer进行读取.properties文件的,但如果项目不允许在配置文件中明文保存 ...
- 黑马-Spring与数据库
Spring与数据库 Spring与jdbc 引入dataSource 在客户端 模板编程 类的结构图, 真正干活的是JdbcTemplate(底层实现,操作 excute方法) JdbcTempla ...
- Spring PropertyPlaceholderConfigurer占位符用法
1.PropertyPlaceholderConfigurer是一个bean工厂后置处理器的实现,也就是BeanFactoryPostProcessor接口的一个实现.PropertyPlacehol ...
随机推荐
- cf Round 603
A.Alternative Thinking(思维) 给出一个01串,你可以取反其中一个连续子串,问取反后的01子串的最长非连续010101串的长度是多少. 我们随便翻一个连续子串,显然翻完之后,对于 ...
- JQuery中each()的使用方法说明
JQuery中each()的使用方法说明 对于jQuery对象,只是把each方法简单的进行了委托:把jQuery对象作为第一个参数传递给jQuery的each方法.换句话说:jQuery提供的eac ...
- EF7 使用 K EF 异常
在使用EF 7 Code first功能时. k ef 报如下错误: 解决办法: 在project.json 同级目录下新建k.cmd,内容如下: "%~dp0approot\runtime ...
- SQLite剖析之编程接口详解
前言 使用过程根据函数大致分为如下几个过程: sqlite3_open() sqlite3_prepare() sqlite3_step() sqlite3_column() sqlite3_fina ...
- GitHub新手快速入门日常操作流程
GitHub新手快速入门日常操作流程 1. 注册帐号 打开https://github.com/,填写注册信息并提交. 2. 登录帐号 打开https://github.com/login,输入注册的 ...
- poj 3680 Intervals
给定N个带权的开区间,第i个区间覆盖区间(ai,bi),权值为wi.现在要求挑出一些区间使得总权值最大,并且满足实轴上任意一个点被覆盖不超过K次. 1<=K<=N<=200.1< ...
- 架构师养成记--4.volatile关键字
volatile修饰的变量可在多个线程间可见. 如下代码,在子线程运行期间主线程修改属性值并不对子线程产生影响,原因是子线程有自己独立的内存空间,其中有主内存中的变量副本. public class ...
- 由于一个粗心造成的RuntimeException
今天在测试时候,老是有一个TextView报错,以下是错误日志: java.lang.RuntimeException: Unable to resume activity {com....Activ ...
- IndentationError: unindent does not match any outer indentation level
[problem] 从别处copy过来的python代码经过自己改动后,运行出错 [解决过程] vim file :set list # cat -A file 也可以 可以看到9-12行的inde ...
- DropDownList控件
1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...