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(){ 。 } }
为什么 能提交到数据库 数据库 也能更新保存 但我配 在 web.xml
<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>
然后 从页面上面调用 后台的 添删改 方法的时候
报错 说我事务 是 read-only 什么的
但我 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(){ 。 } }
为什么 能提交到数据库 数据库 也能更新保存 但我配 在 web.xml
<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>
然后 从页面上面调用 后台的 添删改 方法的时候
报错 说我事务 是 read-only 什么的
解决方案 »
- 一个action跳转到另一个action
- 请过来人告诉我一些关于java学习的适合你自己的且经过实际验证过的好的学习方法和学习经验,先谢谢了!
- 有没有下载java函数库网站
- 求教:我学习J2EE的下一步可以学什么
- 列出jsp连接数据库的方法 除了jdbc和odbc还有什么??
- 第一个EJB运行失败,各位帮忙看看 《急啊!》
- 初级菜鸟 在JBuilder X 中,在它自带的Tomcat4.0中 用JSP 联sqlserver 编码应该没错,不知道问题出在哪
- Serlvet主要是干吗有?怎样才算精通Servlet?
- 我的JAVA入门--我的HELLO WORLD
- 如何将从JSP页面中取得的系统当前时间写入oracle数据库表中?
- Object对象的背后机制
- 在哪里添加事务更好
再 WEB 上面 我没有 帮 SERVICE 加 到事务处理
但 为什么我 写 测试的 那些 类
跑起来就OK的
我想知道 这个是为什么