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&amp;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的更多相关文章

  1. Spring Hibernate JPA 联表查询 复杂查询(转)

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  2. Spring Hibernate JPA 联表查询 复杂查询

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  3. Spring data jpa persistence .xml 配置文件

    <?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://j ...

  4. Spring Boot 应用系列 1 -- Spring Boot 2 整合Spring Data JPA和Druid,双数据源

    最近Team开始尝试使用Spring Boot + Spring Data JPA作为数据层的解决方案,在网上逛了几圈之后发现大家并不待见JPA,理由是(1)MyBatis简单直观够用,(2)以Hib ...

  5. Spring Boot从入门到精通(九)整合Spring Data JPA应用框架

    JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...

  6. Spring Data JPA 整合Spring

    1.1   Spring Data JPA 与 JPA和hibernate之间的关系 JPA是一套规范,内部是有接口和抽象类组成的.hibernate是一套成熟的ORM框架,而且Hibernate实现 ...

  7. 63.JPA/Hibernate/Spring Data概念【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 事情的起源,无意当中在一个群里看到这么一句描述:"有人么?默默的问一句,现在开发用mybatis还是hibernate还是jpa&quo ...

  8. 浅谈jpa、hibernate与spring data jpa三者之间的关系

    1.解释hibernate之前先了解下什么是orm,orm是object relation mapping,即对象关系映射,object可以理解成java实体类Entity,relation是关系型数 ...

  9. 整合Spring Data JPA与Spring MVC: 分页和排序

    之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...

随机推荐

  1. PCR理解

    http://blog.csdn.net/niehanzi/article/details/4450154 PCR的物理意义: PCR存在于TS包的自适应域中,如下图: PCR用来同步前端编码器和后端 ...

  2. tomcat6 配置SSI 支持.shtml文件

    一.修改tomcat-6.0.36\conf\server.xml 文件: 把文件里 ssi 相关的 servlet .servlet-mapping .filter .filter-mapping注 ...

  3. Centos6.4 设置开机自动以某个非root用户启动脚本

    开机自动运行脚本,可以将脚本的执行命令放在 /etc/rc.d/rc.local 文件中,但是这样开机自动运行这个脚本的用户默认为root. 如果想以某个非root用户运行脚本,可以使用如下命令: s ...

  4. $(function(){})里面不能声明定义函数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. poj 3237 Tree(树链剖分,线段树)

    Tree Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 7268   Accepted: 1969 Description ...

  6. bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2277  Solved: 853[Submit][Stat ...

  7. itunes备份文件解析入门

    itunes提供给设备备份的功能,不知道怎么备份的话可以戳一下这个看一下:http://jingyan.baidu.com/article/92255446ea8f46851648f4a4.html ...

  8. SparkContext的初始化过程分析(源码)

     SparkContext的构造函数中,最重要的入参是SparkConf  根据初始化入参生成SparkConf 再根据SparkConf来创建SparkEnv TaskScheduler.start ...

  9. 322. Coin Change

    动态规划里例题,硬币问题. p[i] = dp[i - coin[j]] + 1; 注意i < coin[j] dp[i-coin[j]]无解都要跳过. public class Solutio ...

  10. MVC母版面,子页的脚本生成在最后