Spring+JPA+druid+hibernate配置

编程技术  /  houtizong 发布于 3年前   73
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache"xmlns:jpa="http://www.springframework.org/schema/data/jpa"xsi:schemaLocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd             http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.1.xsd             http://www.springframework.org/schema/aop             http://www.springframework.org/schema/aop/spring-aop-3.1.xsd             http://www.springframework.org/schema/tx              http://www.springframework.org/schema/tx/spring-tx-3.1.xsd          http://www.springframework.org/schema/cache           http://www.springframework.org/schema/cache/spring-cache-3.1.xsd          http://www.springframework.org/schema/data/jpa          http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd"><!-- 数据源配置 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"init-method="init" destroy-method="close"><!-- 驱动名称 --><property name="DriverClassName" value="com.mysql.jdbc.Driver" /><!-- JDBC连接串 --><property name="url"value="jdbc:mysql://192.168.7.7:3306/tmc_db?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull&amp;transformedBitIsBoolean=true" /><!-- 数据库用户名称 --><property name="username" value="root" /><!-- 数据库密码 --><property name="password" value="root" /><!-- 连接池最大使用连接数量 --><property name="maxActive" value="20" /><!-- 初始化大小 --><property name="initialSize" value="5" /><!-- 获取连接最大等待时间 --><property name="maxWait" value="60000" /><!-- 连接池最小空闲 --><property name="minIdle" value="2" /><!-- 逐出连接的检测时间间隔 --><property name="timeBetweenEvictionRunsMillis" value="3000" /><!-- 最小逐出时间 --><property name="minEvictableIdleTimeMillis" value="300000" /><!-- 测试有效用的SQL Query --><property name="validationQuery" value="SELECT 'x'" /><!-- 连接空闲时测试是否有效 --><property name="testWhileIdle" value="true" /><!-- 获取连接时测试是否有效 --><property name="testOnBorrow" value="false" /><!-- 归还连接时是否测试有效 --><property name="testOnReturn" value="false" /></bean><!-- JPA实体工厂配置 --><bean id="entityManagerFactory"class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 扫描实体路径 --><property name="packagesToScan" value="com.spinfosec.dao.entity" /><property name="jpaVendorAdapter"><bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"><property name="showSql" value="true" /><property name="generateDdl" value="false" /></bean></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">validate</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="dataSource" ref="dataSource" /><property name="entityManagerFactory" ref="entityManagerFactory" /></bean><!-- 配置事务传播特性 --><tx:advice id="txAdvice"><tx:attributes><tx:method name="find*" read-only="true" /><tx:method name="*" propagation="REQUIRED" /></tx:attributes></tx:advice><!-- 配置参与事务的类 --><aop:config><aop:pointcut id="dao-tx" expression="execution(* *..dao.impl..*(..))" /><aop:pointcut id="service-tx" expression="execution(* *..service.impl..*(..))" /><aop:advisor pointcut-ref="dao-tx" advice-ref="txAdvice" /><aop:advisor pointcut-ref="service-tx" advice-ref="txAdvice" /></aop:config><!-- 事务注解 --><tx:annotation-driven /></beans>

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客