spring+hibernate+jpa+Druid的配置文件,spring整合Druid
spring+hibernate+jpa+Druid的配置文件
spring+hibernate+jpa+Druid的完整配置
spring+hibernate+jpa+Druid的数据源配置
spring整合Druid,SpringMvc整合Druid,hibernate整合druid
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2016年3月30日 15:46:15 星期三
http://fanshuyao.iteye.com/
全部整合到spring.xml文件,不需要jpa的persistence.xml文件
spring.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
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/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"> <context:property-placeholder location="classpath:jdbc.properties"/> <context:component-scan base-package="com.lqy.spring.iwx.**">
<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> <!-- mysql数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 数据库用户名称 -->
<property name="username" value="${jdbc.username}"/>
<!-- 数据库密码 -->
<property name="password" value="${jdbc.password}"/>
<!-- 驱动名称 -->
<property name="driverClassName" value="${jdbc.driverClassName}" />
<!-- JDBC连接串 -->
<property name="url" value="${jdbc.url}" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="${jdbc.maxActive}" />
<!-- 初始化大小 -->
<property name="initialSize" value="${jdbc.initialSize}" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${jdbc.maxWait}" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${jdbc.minIdle}" />
<!-- 逐出连接的检测时间间隔 -->
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<!-- 最小逐出时间 -->
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
<!-- 测试有效用的SQL Query -->
<property name="validationQuery" value="SELECT 'x'" />
<!-- 连接空闲时测试是否有效 -->
<property name="testWhileIdle" value="true" />
<!-- 获取连接时测试是否有效 -->
<property name="testOnBorrow" value="false" />
<!-- 归还连接时是否测试有效 -->
<property name="testOnReturn" value="false" />
</bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
</bean> <!-- 配置Spring管理Jpa的工厂Bean,需要加入spring-orm-4.1.7.RELEASE.jar(LocalEntityManagerFactoryBean类在里面) -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--待扫描的实体类包,不再需要persistence.xml了-->
<property name="packagesToScan" value="com.lqy.spring.iwx.bean.**"></property>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"></property>
<property name="jpaProperties">
<props>
<!--设置外连接抓取树的最大深度 -->
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">18</prop>
<prop key="hibernate.jdbc.batch_size">10</prop> <!-- 自动建表类型 validate|create|create-drop|update -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- 是否显示SQL -->
<prop key="hibernate.show_sql">false</prop>
<!-- 显示SQL是否格式化 -->
<prop key="hibernate.format_sql">false</prop>
<!-- 关闭二级缓存 -->
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<!-- 关闭实体字段映射校验 -->
<prop key="javax.persistence.validation.mode">none</prop>
</props>
</property>
</bean> <!-- 配置事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean> <!-- 启用事务注解 -->
<!--
Spring事务默认只能对运行时异常(RuntimeException)进行回滚,
不会对Exception进行回滚。
如果需要指定其他异常,则需要配置:rollbackFor=Exception.class
-->
<tx:annotation-driven transaction-manager="transactionManager"/> <task:annotation-driven scheduler="taskScheduler" mode="proxy"/>
<task:scheduler id="taskScheduler" pool-size="10"/> </beans>
springMvc.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.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <context:component-scan base-package="com.lqy.spring.iwx.controller"></context:component-scan> <mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven> <mvc:default-servlet-handler/> <!-- spring3使用-->
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean> --> <!-- spring4使用 -->
<mvc:view-resolvers>
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
</mvc:view-resolvers> </beans>
jdbc.properties配置文件:
#数据源连接配置
jdbc.username=root
jdbc.password=xxx
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8 #<!-- 连接池最大使用连接数量 -->
jdbc.maxActive=20
#<!-- 初始化大小 -->
jdbc.initialSize=2
#<!-- 获取连接最大等待时间 -->
jdbc.maxWait=60000
#<!-- 连接池最小空闲 -->
jdbc.minIdle=0
#<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
jdbc.timeBetweenEvictionRunsMillis=3000
#<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
jdbc.minEvictableIdleTimeMillis=300000
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2016年3月30日 15:46:15 星期三
http://fanshuyao.iteye.com/
spring+hibernate+jpa+Druid的配置文件,spring整合Druid的更多相关文章
- Spring Hibernate JPA 联表查询 复杂查询(转)
今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...
- Spring Hibernate JPA 联表查询 复杂查询
今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...
- Spring data jpa persistence .xml 配置文件
<?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://j ...
- Spring Boot 应用系列 1 -- Spring Boot 2 整合Spring Data JPA和Druid,双数据源
最近Team开始尝试使用Spring Boot + Spring Data JPA作为数据层的解决方案,在网上逛了几圈之后发现大家并不待见JPA,理由是(1)MyBatis简单直观够用,(2)以Hib ...
- Spring Boot从入门到精通(九)整合Spring Data JPA应用框架
JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...
- Spring Data JPA 整合Spring
1.1 Spring Data JPA 与 JPA和hibernate之间的关系 JPA是一套规范,内部是有接口和抽象类组成的.hibernate是一套成熟的ORM框架,而且Hibernate实现 ...
- 63.JPA/Hibernate/Spring Data概念【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 事情的起源,无意当中在一个群里看到这么一句描述:"有人么?默默的问一句,现在开发用mybatis还是hibernate还是jpa&quo ...
- 浅谈jpa、hibernate与spring data jpa三者之间的关系
1.解释hibernate之前先了解下什么是orm,orm是object relation mapping,即对象关系映射,object可以理解成java实体类Entity,relation是关系型数 ...
- 整合Spring Data JPA与Spring MVC: 分页和排序
之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...
随机推荐
- [wikioi]拦截导弹
http://wikioi.com/problem/1044/ 这道题是DP.前一问很自然可以规约成最长不升(含等号下降)子序列.难点在后一问为何能规约成最长上升子序列.后来看了网上的回答,仍然没有简 ...
- USB otg 学习笔记
1 USB OTG的工作原理 OTG补充规范对USB2.0的最重要的扩展是其更具节能性的电源管理和允许设备以主机和外设两种形式工作.OTG有两种设备类型:两用OTG设备(Dualrole device ...
- 远程仓库版本回退方法 good
1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客. 2 问题 如果提交了一个错误的版本,怎么回退版本? 如果提交了一个错误的版本到远程分支,怎么回退远程分支 ...
- 使用jconsole检测linux服务器
在Jboss中运行run.sh的脚本下添加如下信息: #add by step #start JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxre ...
- SQL SERVER 自定义函数 整数转成指定长度的16进制 转换成指定长度的16进制 不足补0
最近做项目扩展的时候,遇到问题就是将整型转换成指定长度的16进制 刚开始就是直接使用 cast(12 as varbinary(4))但是发现这个不能解决我的问题 所以就上网搜了一下,然后改了改,下面 ...
- uva 10047 the monocyle (四维bfs)
算法指南白书 维护一个四维数组,走一步更新一步 #include<cstdio> #include<cstring> #include<queue> #includ ...
- HTC仅限拨打紧急电话
问题描述: 我手上有台 HTC One V 没碰没撞,突然打不出电话,信号上显示一个叉,屏幕上显示“仅限拨打紧急电话” 解决办法:经百度,原来很多HTC机子都有这种情况,幸好不是硬件坏了,只需按以下步 ...
- 转载:Python中的new style class机制实现
1.Python中的对象模型python中所有东西都是对象 class对象:表示Python内置的类型和定义的类型instance对象(实例对象):表示由class对象创建的实例 1.1 对象间的关系 ...
- Implement the hash table using array / binary search tree
今天在复习Arrays and String 时看到一个很有趣的问题.希望跟大家分享一下. Implement the hash table using array / binary search t ...
- POI2001 金矿
问题描述 金矿的老师傅年底要退休了.经理为了奖赏他的尽职尽责的工作,决定在一块包含 n(n ≤ 15000) 个采金点的长方形土地中划出一块长度为 S ,宽度为 W 的区域奖励给他(1 ≤ s , w ...