spring 配置文件
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义事务传播属性-->
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="finds*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="merge*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean> <!-- 定义BeanNameAutoProxyCreator-->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定对满足哪些bean name的bean自动生成业务代理 -->
<property name="beanNames">
<value>*ServiceImpl</value>
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<!-- 此处可增加其他新的Interceptor -->
<value>serviceInterceptor</value>
<value>transactionInterceptor</value>
<value>exceptionInterceptor</value>
</list>
</property>
</bean>
但我 servicebean 是这么写的
<bean id="itemManagementService" class="net.carefx.cp.service.impl.ItemManagementServiceImpl">
</bean>
我开始 是这样写的事务 不就应该没有被管理
但为什么我写测试的时候 public class ItemManagementServiceTest
{
private static ItemManagementService itemManagementService; @BeforeClass
public static void setUpBeforeClass () throws Exception
{
ApplicationContext applicationContext = new ClassPathXmlApplicationContext (
"/net/carefx/cp/property/applicationContext.xml");
itemManagementService = (ItemManagementService) applicationContext.getBean ("itemManagementService");
}
@Test
public void testSaveItem(){
。
}
}
为什么 能提交到数据库 数据库 也能更新保存
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义事务传播属性-->
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="finds*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="merge*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean> <!-- 定义BeanNameAutoProxyCreator-->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定对满足哪些bean name的bean自动生成业务代理 -->
<property name="beanNames">
<value>*ServiceImpl</value>
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
<property name="interceptorNames">
<list>
<!-- 此处可增加其他新的Interceptor -->
<value>serviceInterceptor</value>
<value>transactionInterceptor</value>
<value>exceptionInterceptor</value>
</list>
</property>
</bean>
但我 servicebean 是这么写的
<bean id="itemManagementService" class="net.carefx.cp.service.impl.ItemManagementServiceImpl">
</bean>
我开始 是这样写的事务 不就应该没有被管理
但为什么我写测试的时候 public class ItemManagementServiceTest
{
private static ItemManagementService itemManagementService; @BeforeClass
public static void setUpBeforeClass () throws Exception
{
ApplicationContext applicationContext = new ClassPathXmlApplicationContext (
"/net/carefx/cp/property/applicationContext.xml");
itemManagementService = (ItemManagementService) applicationContext.getBean ("itemManagementService");
}
@Test
public void testSaveItem(){
。
}
}
为什么 能提交到数据库 数据库 也能更新保存
解决方案 »
- ActionContext类有这个getContext()方法,怎么方法后面有有方法啊,这是什么逻辑?
- Spring注解实现 分主键一对多双向关联
- Panel类不能使用MouseListener吗?
- 求 open session in voiw 解决方案
- 谁做过 web应用 与 openfire集成啊 给点文档和例子
- jsp web生成word文档时出现乱码?《十万火急》
- 如何检测WebService异常和性能
- 关于tomcat5.5配置数据源的问题,请问应该如何配置?多谢了!
- 求助
- XPath的扩展名问题?
- 关于struts2模型驱动的问题,好心人帮个忙把!!!谢谢啦
- 如何使用shell文件实现linux环境下的挂载功能,具体代码!!
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/net/carefx/cp/property/applicationContext.xml</param-value>
</context-param>
那不就能读到 spring 的配置
然后 网页上面调用 了
后台的 save update 方法
就会报错 说一个事务是 read-only 什么的 错误!