<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!--组件扫描(扫描除了@Controller和@ControllerAdvice以外的其它的类)-->
<context:component-scan base-package="com.test.shop">
<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>
<!--配置分散配置的属性文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--配置开发环境C3P0数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="minPoolSize" value="${jdbc.minPoolSize}"/>
<property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>
<property name="maxIdleTime" value="${jdbc.maxIdleTime}"/>
<property name="acquireIncrement" value="${jdbc.acquireIncrement}"/>
<property name="maxStatements" value="${jdbc.maxStatements}"/>
<property name="initialPoolSize" value="${jdbc.initialPoolSize}"/>
<property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}"/>
<property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}"/>
<property name="breakAfterAcquireFailure" value="${jdbc.breakAfterAcquireFailure}"/>
<property name="testConnectionOnCheckout" value="${jdbc.testConnectionOnCheckout}"/>
</bean>
<!--JPA实体管理器工厂 Spring整合JPA的核心入口-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!--指定持久化实现厂商类-->
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence"/>
</property>
<!--设置JPA实现厂商的特定属性-->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false"/>
<property name="database" value="MYSQL"/>
</bean>
</property>
<!--指定一些高级特性-->
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
<!--扫描的包-->
<property name="packagesToScan" value="com.test.shop.domain"/>
<!--JPA实现厂商类的特有属性-->
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
</bean>
<!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!--事务通知-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="save*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="insert*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="remove*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="edit*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="modify*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="batch*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="load*" isolation="DEFAULT" propagation="REQUIRED" read-only="true"/>
<tx:method name="get*" isolation="DEFAULT" propagation="REQUIRED" read-only="true"/>
<tx:method name="find*" isolation="DEFAULT" propagation="REQUIRED" read-only="true"/>
<tx:method name="list*" isolation="DEFAULT" propagation="REQUIRED" read-only="true"/>
<tx:method name="*" isolation="DEFAULT" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置AspectJ AOP配置-->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
</aop:config>
</beans>
分享到:
相关推荐
Spring集成JPA和MyBatis简单例子
NULL 博文链接:https://panshaobinsb.iteye.com/blog/1683979
使用Myeclipse6.x开发 spring整合JPA的例子 需要自己导组件包 然后将原代码放到相应的目录下 刚刚写完, 别忘了顶一下
spring整合jpa简单实例,本人亲测正式有效,导入成功即可运行。
新的持久化api,低耦合,方便,快速。项目为Intellij idea项目。
Spring集成JPA和MyBatis简单例子
Spring集成Jpa(Hibernate实现)例子,原代码哦~! 包涵所需要的jar包,这些jar包不好找,版本如果不兼容就会出现各种各样的莫名其妙的错误或异常。
spring整合jpa,分为jpa和spring两部分,用entitymanage来进行数据库的持久化操作,spring利用注解的方式,jpa也是用注解的方式,里面有测试,已成功!
该案例使用SpringBoot 整合了SPringData JPA,使用SpringData 开发简化了Dao层的开发量,简化了数据访问,使得持久化更加简单 !
技术架构:SpringMVC3+Spring3.1.2+Spring Data JPA+Maven 声明:该应用仅仅是技术研究:Spring Data JPA的配置和常见api的使用&maven构建项目,其他技术不在此研究 内涵sql和各种Spring Data JPA测试和案例,导入&...
第四章节 Spring Boot 整合 Spring Data JPA(SpringBoot 高级)一、Spring Data JPA 介绍Spring Dat
Spring Boot 集成 JPASpring Boot 集成 JPASpring Boot 集成 JPASpring Boot 集成 JPASpring Boot 集成 JPASpring Boot 集成 JPA
前几天单独做了jpa操作数据的demo,今天把spring整合了进来用spring+jpa的方式重新做了一套案例;期间各种jar包不完整报错;错误分析受益匪浅,终整合成功、以上是我整理的代码。基本的功能都已实现,想拓展的同学...
NULL 博文链接:https://mixo44.iteye.com/blog/1797079
2017 spring data jpa+spring4.2+springmvc+hibernate4.3 maven环境intellij idea增删改查实例
NULL 博文链接:https://pihai.iteye.com/blog/403437
Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA
基础框架,可满足开发需要
idea下整合springboot+spring data jpa