applicationContext.xml
2014-03-19 21:29
375 查看
<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: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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:annotation-config />
<!-- 扫描com.liuruichao包下得所有类 -->
<context:component-scan base-package="com.liuruichao" />
<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.liuruichao.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<aop:config>
<!--定义需要进行切面编程的所有方法,定义成为一个id是nicai的bean 代表了多有的方法 -->
<aop:pointcut id="bussinessService"
expression="execution
(public * com.liuruichao.service.*.*(..))" />
<!-- id是txAdvice的bean 切入 id是nicai的所有方法 把他们俩整合到一起 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/>
</aop:config>
<!-- 定义一个指导意见(在某些方法执行前执行)提高效率的 代表了所要加入的切面 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
</tx:attributes>
</tx:advice>
</beans>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"
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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:annotation-config />
<!-- 扫描com.liuruichao包下得所有类 -->
<context:component-scan base-package="com.liuruichao" />
<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.liuruichao.model</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<aop:config>
<!--定义需要进行切面编程的所有方法,定义成为一个id是nicai的bean 代表了多有的方法 -->
<aop:pointcut id="bussinessService"
expression="execution
(public * com.liuruichao.service.*.*(..))" />
<!-- id是txAdvice的bean 切入 id是nicai的所有方法 把他们俩整合到一起 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService"/>
</aop:config>
<!-- 定义一个指导意见(在某些方法执行前执行)提高效率的 代表了所要加入的切面 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
</tx:attributes>
</tx:advice>
</beans>
相关文章推荐
- ASP.NET MVC 3:放弃 Unity
- 推荐一款系统软件:Unity tweak tool
- 向Android系统自带的联系人界面添加数据
- 配置android开发环境至运行第一个程序
- Android开发之自定义字体
- 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第七章 深入理解Wi-Fi P2P
- Android学习之——(3)项目中的WebService返回数据处理学习
- Android Dialog
- iOS study Day 2
- Android学习笔记:用JSON封装JavaBean传输
- 通过自定义的URL Scheme启动你的App
- Android View绘制过程
- Android View绘制过程
- Android progressBar 自定义
- ios学习临时笔记-CGContext学习
- 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第六章 深入理解wi-Fi Simple Configuration
- 如何在FireFox浏览器上访问微信公共账户提供的链接
- iPhone中的UIApplication详解
- 30 Great Open Source Mac Apps
- Android发送短信