springMVC+JAP整合彻底摆脱persistence.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>
<!--http://www.cnblogs.com/qgc88/-->
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
<property name="packagesToScan" value="com.jubangit.smartbusiness.database.entity"/> <!--如果删除了persistence.xml,则需要指定实体所在的路径否则会报找不到该文件-->
<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>
springMVC+JAP整合彻底摆脱persistence.xml配置文件的更多相关文章
- spring与jpa整合 简化persistence.xml配置文件 使用属性文件 数据源dbcp访问数据库
===========appliction.xml配置文件======================= <?xml version="1.0" encoding=" ...
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释(转)
原文:https://blog.csdn.net/yijiemamin/article/details/51156189# 这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文 ...
- 0927-转载:SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
这篇文章暂时只对框架中所要用到的配置文件进行解释说明,而且是针对注解形式的,框架运转的具体流程过两天再进行总结. spring+springmvc+mybatis框架中用到了三个XML配置文件:web ...
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文件并没有进行过多的说明,很多人知其然不知其所以然,经过几天的搜索和整理,今天总算对其中的XML配置文件有了一定的了解,所以拿 ...
- Jpa规范中persistence.xml 配置文件解析
使用spring data + hibernate 进行逻辑层操作时候需要配置 persistence.xml的内容 <?xml version="1.0"?> & ...
- Spring data jpa persistence .xml 配置文件
<?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://j ...
- springmvc中整合mongodb副本集配置文件
配置文件jdbc.properties: mongo.hostport=192.168.100.100:28007,192.168.100.110:28008,192.168.100.120:2800 ...
- persistence.xml文件的妙处
在上家公司,经常要做的一个很麻烦的事就是写sql脚本, 修改了表结构,比如增加一个新字段的时候,都必须要写sql并放入指定目录中, 目的就是为了便于当我们把代码迁移到其他数据库中的时候,再来执行这些s ...
- [转]用jpa创建web项目,报错:No persistence units parsed from {classpath*:META-INF/persistence.xml}
原文地址:http://blog.sina.com.cn/s/blog_6826662b01015opk.html 最近做一个web项目用到了Spring+JPA,由于没有正确配置persistenc ...
随机推荐
- Android failed creating starting window
/***************************************************************************** * Android failed crea ...
- Myeclipse提示失效?
- python tile函数用法
tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...
- xcode的ios工程目录结构
目录结构: a.supporting files: main.m和资源文件 xxx-info.plist:包含应用程序相关属性列表,如版本,程序名等 .pch文件:预编译头文件,相当于MFC里的std ...
- vim的保存误认为utf8问题
用vim改脚本改到一处写到'太原':w一下,再打开,,结果给乱码了...我默认sql是用cp936的,,,想到到和记录本的联通问题一样.... 可能会问我为什么不用utf8,,,,因为ms200 ...
- Linux makefile教程之使用变量五[转]
使用变量 ———— 在 Makefile中的定义的变量,就像是C/C++语言中的宏一样,他代表了一个文本字串,在Makefile中执行的时候其会自动原模原样地展开在所使 用的地方.其与C/C++所不同 ...
- 让 PowerDesigner 支持 SQLite!
让 PowerDesigner 支持 SQLite! PowerDesigner是一个功能强大的数据库设计软件,最近正在用其设计新系统的数据库,但由于在项目初级阶段,希望使用轻量级的 SQLite ...
- Linux上修改weblogic的内存大小
我们经常在使用WebLoigc部署应用程序后,发现程序运行速度并不是很快,遇到这种情况我们可以尝试调整启动时分配的内存,设置方法有两种: 一.在../domain/setDomainEnv.sh文件中 ...
- CSS width:100%和width:auto的区别
width:100%和width:auto的区别 width:auto比较聪明,如果margin已经左右占去10px的空间,那么width给的值就是580px. <style> div{ ...
- ASP.NET MVC 常用内置验证特性 简介
1.[Required] : 必须输入 [Required(ErrorMessage = "请输入用户名")] 2.[StringLength] : 限制字符串长度 [String ...