===========appliction.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:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-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/aop
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    ">

<!-- 自动扫描所有注解该路径 --> 
 <context:component-scan base-package="com.jubangit.smartbusiness.*" />
  <context:property-placeholder location="classpath:/META-INF/db.Properties" /><!--连接数据库的属性文件的路径-->

<!-- 定义跳转的文件的前后缀 -->
 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="suffix" value=".jsp" /> <!-- 指定跳转的页面为.jsp格式 -->
 </bean>
 
 <!-- JPA Entity Manager Factory -->
 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource"
  p:persistenceXmlLocation="classpath:/META-INF/persistence.xml" p:persistenceUnitName="jub"><!--p:persistenceXmlLocation="META-INF/persistence.xml" p:persistenceUnitName="jub",可以不加,应用服务器会扫描src/META-INF/persistence.xml-->
   <!-- <property name="packagesToScan" value="org.springside.examples.quickstart"/> --><!--Weblogic/Jboss这些自带JPA支持的应用服务器有时候会扫描persistence.xml,因此彻底删除掉这个文件需要加,否则会报错;但是删除persistence.xml,JPA找不到注解的实体类,所有还需要保留此文件-->
  <property name="jpaDialect">
   <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  </property>
  <property name="loadTimeWeaver">
   <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
  </property>
  <property name="persistenceProvider">
   <bean class="org.hibernate.ejb.HibernatePersistence"/><!-- 用于指定持久化实现厂商类 -->
  </property>
  
   <property name="jpaProperties">
             <props>
             <prop key="hibernate.dialect">${dialect}</prop>
       <prop key="hibernate.show_sql">true</prop>
                  <prop key="hibernate.max_fetch_depth">3</prop>
                  <prop key="hibernate.jdbc.fetch_size">18</prop>
                  <prop key="hibernate.jdbc.batch_size">10</prop>
     <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --><!-- 定义是否自动生成表,create表示每次加载都重新生成,update表示每次加载只是更新表 -->
               </props>
           </property>
 </bean>
 
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><!--dbcp连接池-->
  <property name="driverClassName"><value>${driver}</value></property>
  <property name="url"><value>${url}</value></property>
  <property name="username"><value>${uname}</value></property>
  <property name="password"><value>${pwd}</value></property>
   <property name="initialSize"><value>5</value></property>
   <property name="maxActive"><value>50</value></property>
   <property name="maxIdle"><value>10</value></property>
   <property name="minIdle"><value>5</value></property>
    </bean>
   
    <!--事物-->
 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory" />
 </bean>
 <!-- 事物通知 -->
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="sav*" propagation="REQUIRED" rollback-for="Exception" /> <!-- rollback-for回滚事物,果存在一个事务,则支持当前事务。如果没有事务则开启 -->
   <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
   <tx:method name="updat*" propagation="REQUIRED" rollback-for="Exception" />
   <tx:method name="qry*" propagation="NOT_SUPPORTED" read-only="true"/>
   <tx:method name="*" propagation="NOT_SUPPORTED" read-only="true"/>  <!--必须要加propagation否则存在事物依然执行,NOT_SUPPORTED总是非事务地执行,并挂起任何存在的事务 -->
  </tx:attributes>
 </tx:advice>
 <!-- 事物切入 -->
 <aop:config>
  <aop:pointcut id="cut"
   expression="execution(* com.jubangit.smartbusiness.services.impl.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="cut" />
 </aop:config>

</beans>

=================persistence.xml配置文件=================================

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd "
 version="2.0">
 <persistence-unit name="jub" transaction-type="RESOURCE_LOCAL"/>
</persistence>

spring与jpa整合 简化persistence.xml配置文件 使用属性文件 数据源dbcp访问数据库的更多相关文章

  1. Jpa规范中persistence.xml 配置文件解析

    使用spring data + hibernate 进行逻辑层操作时候需要配置 persistence.xml的内容   <?xml version="1.0"?> & ...

  2. springMVC+JAP整合彻底摆脱persistence.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  3. JPA 不在 persistence.xml 文件中配置每个Entity实体类的2种解决办法

    在Spring 集成 Hibernate 的JPA方式中,需要在persistence配置文件中定义每一个实体类,这样非常地不方便,远哥目前找到了2种方法.   这2种方式都可以实现不用persist ...

  4. Spring根据XML配置文件注入属性 其实也是造bean,看看是使用constructor还是setter顺带完成属性赋值

    方法一使用setter方法 package com.swift; public class Book { private String bookName; public void setBook(St ...

  5. spring data mongodb中,如果对象中的属性不想加入到数据库字段中

    spring data mongodb中,如果对象中的属性不想加入到数据库字段中,可加@Transient注解,声明为透明属性 spring data mongodb 官网帮助文档 http://ww ...

  6. //读取配置文件(属性文件)的工具类-ConfigManager

    package com.pb.news.util; import java.io.IOException;import java.io.InputStream;import java.sql.Resu ...

  7. Spring Data JPA 整合Spring

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

  8. Spring Data JPA 整合Spring 第二篇

    主要是在CustomerDao中去写一些代码,在调用Query中去用SQL 例如 public interface CustomerDao extends JpaRepository<Custo ...

  9. SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释(转)

    原文:https://blog.csdn.net/yijiemamin/article/details/51156189# 这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文 ...

随机推荐

  1. NBUT 1122 Shameimaru's Candid Camera(水)

    题意: 给n*m个格子,初始时每个格子中有个数值为0,部分格子中含有炸弹,每个炸弹爆炸可以将周围的8个非炸弹格子中的数值加1,求全部炸弹炸完后那些非0且非炸弹格子中的数是多少. 思路: 另开一个矩阵, ...

  2. python练习程序(c100经典例19)

    题目: 一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程找出1000以内的所有完数. def foo(a): sra=a; lis=[1]; while 1: for i ...

  3. 15个必须知道的chrome开发者技巧(转)

    15个必须知道的chrome开发者技巧 在Web开发者中,Google Chrome是使用最广泛的浏览器.六周一次的发布周期和一套强大的不断扩大开发功能,使其成为了web开发者必备的工具.你可能已经熟 ...

  4. 【转】Mac OS X开机启动Path had bad permissions错误解决方案

    原文网址:http://www.07net01.com/2015/07/884646.html 最近在安装mongodb的时候遇到了上述提示,在国内各大网站寻找解决方案无果,于是果断查看国外的网站,终 ...

  5. java 构造函数内部的多态方法 完全剖析

    我们先来看一个例子,如果你读过<java编程思想>的话 应该会有印象 package com.test.zj; public class PolyConstructors { public ...

  6. Python time mktime()方法

    描述 Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数. 如果输入的值不 ...

  7. Shell教程1​-第一个Shell脚本

    打开文本编辑器,新建一个文件,扩展名为sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好,如果你用php写shell 脚本,扩展名就用php好了.输入一些代码: #!/bin/bash ...

  8. 开源Math.NET基础数学类库使用(11)C#计算相关系数

    阅读目录 前言 1.Math.NET计算相关系数的类 2.Correlation的实现 3.使用案例 4.资源                本博客所有文章分类的总目录:[总目录]本博客博文总目录-实 ...

  9. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  10. [python]Python操作MySQL

    [安装] 安装MySQL 安装MySQL不用多说了,下载下来安装就是,没有特别需要注意的地方. 一个下载地址:点击打开链接 [样例] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...