Spring中怎么使用事务呢
解决方案 »
- extjs动态添加组件为什么没有效果
- 紧急求助,session在weblogic8下发生突变!!!
- 关于后台左面树形菜单实现问题!
- java 模板 博客
- 怎样把左边的下拉框内容添加到右边的下拉框,而且是选多个,还有怎样从右边的下拉框移除对象,最好用div 方法
- 大家好,有个清空缓存的问题
- 是不是在jsp中,如果这个字段在数据库里是表的外键,那么他只能用下拉列表,不能用文本框显示?
- 高手过来瞧一下!
- 关于跳转的问题(包含中文url的问题)
- mybatisGenerator逆向工程,mapper接口无法生成类注解,注释
- tomcat配置后出现The requested resource (/host-manager/) is not available,望高手们解疑!
- 有人用过DOJO没,怎么用
<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"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- 配置接口UserServer -->
<bean id="UserServer" class="com.feng.aop.UserServerImpl"></bean>
<!-- 配置关注点 -->
<bean id="SecurtyHandler" class="com.feng.aop.SecurtyHandler"></bean>
<!-- AOP的配置 -->
<aop:config>
<!-- 切点的配置,当切点位于方面外时,此切点可以被所有的方面所共享 -->
<aop:pointcut id="del"
<!-- 切点表达式,用于配对连接点(方法)是否符合表达式的定义 -->
<!-- 第一个*表示方法的返回值,del*表示配对以del开头的所有方法,最后..表示方法的参数可以为任意类型 -->
expression="execution(*
com.feng.aop.UserServerImpl.del*(..))" />
<!-- 方面配置,一个方面用于处理相同类型的功能的模块 -->
<aop:aspect id="allMethod" ref="SecurtyHandler">
<aop:pointcut id="query"
expression="execution(* com.feng.aop.UserServerImpl.query*(..))" />
<!-- 通知的使用,当某个切点的表达式成立时,即调用此通知注入的方法 -->
<aop:before method="check" pointcut-ref="query" />
<aop:before method="check" pointcut-ref="del" />
</aop:aspect>
</aop:config>
</beans>
<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><!-- !定义单个jdbc数据源的事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean><!—定义拦截器-->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean><!—定义业务对象-->
<bean id="com.prs.application.ehld.sample.biz.service.sampleService.target"
class="com.prs.application.ehld.sample.biz.service.impl.SampleServiceImpl">
<property name="userInfoDAO"
ref="com.prs.application.ehld.sample.integration.dao.userInfoDAO">
</property>
</bean><!—定义业务对象的事务代理对象-->
<bean id="com.prs.application.ehld.sample.biz.service.sampleService" class="org.springframeword.aop.framework.ProxyFacgtoryBean">
<property name="target"
ref="com.prs.application.ehld.sample.biz.service.sampleService.target">
</property>
<property name="interceptorNames">
<value>transactionInterceptor</value>
</property>
</bean>
搞错了,呵呵http://blog.csdn.net/sghys/article/details/1916278
以下是我自己一个学习项目的代码,希望对大家有所帮助.<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <context:annotation-config />
<context:component-scan base-package="com.kzl" /> <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean> <bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"></property>
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>com.kzl.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property> </bean> <aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.kzl.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="getUser" read-only="true" />
<tx:method name="add*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice></beans>