Spring配置数据库连接
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-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/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.2.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="false"/>
<property name="locations">
<list>
<value>classpath*:/dbConfig.properties</value>
<value>classpath*:/security-config.properties</value>
<value>classpath*:/led_mq_config.properties</value>
</list>
</property>
</bean> <!-- 注解扫描的包 -->
<!-- <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
<context:component-scan base-package="cn.com.digicube">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- uses @Transactional sign -->
<mvc:annotation-driven/>
<!-- uses @AspectJ sign-->
<aop:aspectj-autoproxy/>
<task:annotation-driven /> <!-- 配置数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close">
<property name="driverClassName" value="${operation.hibernate.driverClassName}"/>
<property name="url" value="${operation.hibernate.connection.url}"/>
<property name="username" value="${operation.hibernate.connection.username}"/>
<property name="password" value="${operation.hibernate.connection.password}"/>
<property name="maxActive" value="256"/>
<property name="initialSize" value="16"/>
<property name="maxWait" value="60000"/>
<property name="minIdle" value="16"/>
<property name="dbType" value="sqlserver"/>
<!--<propenamename="dbType" value = "sqlserver" />--> <property name="timeBetweenEvictionRunsMillis" value="3000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/> <property name="removeAbandoned" value="true"/>
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandonedTimeout" value="1800"/>
<!-- 1800秒,也就是30分钟 -->
<property name="logAbandoned" value="true"/>
<!-- 关闭abanded连接时输出错误日志 --> <property name="validationQuery" value="SELECT 1"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<!-- mysql 不支持 poolPreparedStatements <propenamename="poolPreparedStatements"
value="true" /> <propenamename="maxPoolPreparedStatementPerConnectionSize"
value="20" /> -->
<!-- 配置过滤器:wall——防注入攻击(WallFilter默认的防注入配置,也可以自己另外配置),stat-监控统计功能 -->
<property name="filters" value="wall,stat"/>
</bean> <bean id="customNamingStrategy" class="cn.telemedias.commons.api.commons.extension.CustomNamingStrategy"></bean>
<!-- 配置hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="namingStrategy" ref="customNamingStrategy"/>
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${operation.hibernate.dialect}</prop>
<!-- <prop key="hibernate.default_schema">${hibernate.default_schema}</prop>-->
<prop key="hibernate.show_sql">${hibernate.connection.show_sql}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.format_sql">${hibernate.connection.format_sql}</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<!--
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</prop>
-->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.SingletonEhCacheRegionFactory
</prop>
<!-- 二级缓存EhCache配置 -->
<!--<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>-->
<!--<prop key="hibernate.cache.provider_class">${hibernate.cache.region.factory_class}</prop>-->
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:ehcache.xml</prop>
<!-- 项目启动时初始化CurrentSessionContext,用于获取session(sessionFactory.getCurrentSession()) -->
<prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>cn.com.itmy</value>
</list>
</property>
</bean> <!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 开启aop -->
<aop:config proxy-target-class="true"><!-- expose-proxy="true"-->
<aop:pointcut id="txPointcut" expression="execution(* cn.*.*.service..*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config> <bean class="cn.telemedias.commons.api.commons.context.SystemContext" lazy-init="false"/>
<import resource="classpath:applicationContext-cache.xml"/>
<import resource="classpath:applicationContext-shiro.xml"/>
<import resource="classpath:applicationContext-mq.xml"/>
</beans>
Spring配置数据库连接的更多相关文章
- Druid + spring 配置数据库连接池
1. Druid的简介 Druid是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,包括DBCP.C3P0.BoneCP.Proxool.JBo ...
- Spring配置-数据库连接池proxool[转]
数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是针对这个问题提出 ...
- spring配置数据库连接池druid
连接池原理 连接池基本的思想是在系统初始化的时候,将数据库连接作为对象存储在内存中,当用户需要访问数据库时,并非建立一个新的连接,而是从连接池中取出一个已建立的空闲连接对象.使用完毕后,用户也并非将连 ...
- spring配置数据库连接池
1. jdbcConfig.properties文件中 jdbc.jdbcUrl=jdbc:mysql:///ssm-crudjdbc.driverClass=com.mysql.jdbc.Drive ...
- Spring配置连接池
---------------------siwuxie095 Spring 配置连接池 1.Spring 配置内置连接 ...
- Spring配置文件中如何使用外部配置文件配置数据库连接
直接在spring的配置文件中applicationContext.xml文件中配置数据库连接也可以,但是有个问题,需要在url后带着使用编码集和指定编码集,出现了如下问题,&这个符号报错-- ...
- SpringBoot学习(三)-->Spring的Java配置方式之读取外部的资源配置文件并配置数据库连接池
三.读取外部的资源配置文件并配置数据库连接池 1.读取外部的资源配置文件 通过@PropertySource可以指定读取的配置文件,通过@Value注解获取值,具体用法: @Configuration ...
- spring配置详解
1.前言 公司老项目的后台,均是基于spring框架搭建,其中还用到了log4j.jar等开源架包.在新项目中,则是spring和hibernate框架均有使用,利用了hibernate框架,来实现持 ...
- java配置数据库连接池的方法步骤
java配置数据库连接池的方法步骤 java配置数据库连接池的方法步骤,需要的朋友可以参考一下 先来了解下什么是数据库连接池数据库连接池技术的思想非常简单,将数据库连接作为对象存储在一个Vecto ...
- Spring的DataSource配置、将Hibernate配置所有写到Spring配置
DataSource能够集中管理数据库连接,降低维护工作量,使部署更简单: Spring的DataSource配置:(Spring数据源配置)这里使用dbcp,还有非常多其它的如c3p0,jdbc,j ...
随机推荐
- Windows快捷键学习
Ctrl组合 Ctrl+C 复制 Ctrl+X 剪切 Ctrl+V 粘贴 Ctrl+A 全选 Ctrl+Z 撤消 Ctrl+S 保存 Shift组合 Shift+Delete 永久删除 Shift+A ...
- 插入Mybatis教学
------------恢复内容开始------------ 1.Mybatis的CRUD 首先第一点要注意: namespace中的包名称,一定要和mapper接口的包名称要一一对应. 有上面的图可 ...
- 1.1 [zabbix5.4]-部署
一.从容器安装 1.0 官网 https://www.zabbix.com/documentation/5.0/zh/manual/installation/containers # 官方文档 h ...
- mfc edit只允许输入数字
1.给EDIT控件添加 EN_CHANGE 事件 2.事件中的代码如下: 1 CString strEditVidoe; 2 GetDlgItem( iId )->GetWindowText( ...
- VSCode 快捷键,简化操作
一. 区域代码快捷键 1. 折叠所有 折叠所有区域代码的快捷: ctrl + k ctrl + 0 ; 展开所有折叠区域代码的快捷:ctrl +k ctrl + J ; 2. 按层 ...
- 11.4 显示窗口(harib08d)11.5 小实验(hearib08e) 11.6 高速计数器(harib08f)
11.4 显示窗口(harib08d) 书P206 11.5 小实验(hearib08e) 书P208 11.6 高速计数器(harib08f) 书P209
- LightOJ1298 One Theorem, One Year (欧拉函数dp)
题意:给你almost-K-First-P-Prime, 如果一个数x有k个质因子,且这k个质因子包含且仅包含前p个质数满足条件. 让你求Σφ(x): 思路:首先我们这p个因子一定要有,也就是剩下k- ...
- Day05笔记
01.数组类(了解) 1.目的:设计一个类,该类有数组的功能,可以存储数据,可以删除修改数据 2.设计核心数据 1.属性:指针(指向堆区空间),数组实际存储的元素个数,数组容量 2.方法:构造(开辟堆 ...
- 自己动手从零写桌面操作系统GrapeOS系列教程——19.硬盘读写理论知识
学习操作系统原理最好的方法是自己写一个简单的操作系统. 一.硬盘控制器 我们前面已经讲过硬盘控制器是一种I/O接口,CPU通过它就能间接的读写硬盘.硬盘控制器主要有IDE和SATA两种,我们这里只考虑 ...
- Linux的优缺点
作为一个Archlinux用户, 断然是不会认为Linux有缺点的, 任何所谓的缺点都是自己技艺不精或者没有好好利用搜索引擎而造成的狭隘偏见. 但是假如是一位习惯于视窗系统的新手而言, 假如他上手的是 ...