opensessioninview跟请求转发是事务的问题
我想问一下 使用 opensessioninviewfilter 的时候请求提交到 一个action 调用了 service 的一个方法 进行一些数据库的操作
然后 请求转发到 另一个 action 又调用一个 service的方法 再进行一些数据库的操作
这样做有问题吗
为什么 在请求转发知道的操作里会报
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.NullPointerException
这样的错误呢
@Controller("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport {
private Service userService;
public String method1() throws Exception {
userService.method1();
return "success";
}
public String method2() throws Exception {
userService.method2();
return "success";
}
@Resource(name = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
}
@Service("userService")
public class UserServiceImpl implements UserService {
private UserDao userDao;
public UserStatus method1(User user) {
//dao操作
}
@Override
public User method2(User user) {
//dao操作
}
@Resource(name = "userDao")
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
}
<action name="action1" class="userAction" method="method1">
<result name="success" type="chain">
<param name="">action2</param>
</result>
<result name="input">/WEB-INF/page/user/register.jsp</result>
</action>
<action name="action2" class="userAction" method="method2">
<result name="success" type="redirectAction">
<param name="namespace">/user</param>
<param name="actionName">action3</param>
</result>
</action>
<tx:annotation-driven transaction-manager="txManager" />
<aop:config>
<aop:pointcut expression="execution(* com.bookshop.service..*(..))"
id="serviceMethod" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
我觉的数据库的有关配置是正确的 因为在不是请求转发的情况下都不会出问题
opensessioninview --------------------编程问答-------------------- 贴出我这样做的异常信息
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.NullPointerException
org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:428)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy13.codeSend(Unknown Source)
com.bookshop.action.UserAction.codeSend(UserAction.java:57)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
... .....
补充:Java , Web 开发