- <?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>
spring+hibernate+jpa+Druid的配置文件,spring整合Druid
最新推荐文章于 2019-08-13 20:20:34 发布