我已经配置了事物为什么还是报错Write operations are not allowed in read-only mode (FlushMode.MAN

willxuecn 2015-10-20 10:18:07
用户登陆,插入日志信息
public String execute() throws Exception {
try {
HttpServletRequest request = ServletActionContext.getRequest();
Loginlog loginlog = new Loginlog(user.getUname(), new Timestamp(new Date().getTime()), request.getRemoteAddr());
User users = this.userService.userLogin(user, loginlog);
ServletContext servletContext = ServletActionContext.getServletContext();
HttpSession existSession = (HttpSession) servletContext.getAttribute(this.user.getUname());
if (existSession != null) {
existSession.invalidate();
servletContext.removeAttribute(this.user.getUname());
}
HttpSession session = request.getSession();
session.setAttribute(Constant.LOGIN_USER, users);
servletContext.setAttribute(this.user.getUname(), session);
} catch (UserNotFoundException e) {
this.msg = e.getMessage();
return INPUT;
}
return SUCCESS;
}


service
@Override
public User userLogin(User user, Loginlog loginlog) {
User u = this.userDao.get(user.getUname());
if (u == null || u.getUname().length() <= 0) {
throw new UserNotFoundException(Constant.USER_LOGIN_KEY_UNAME);
} else {
if (!u.getPwd().equals(user.getPwd())) {
throw new UserNotFoundException(Constant.USER_LOGIN_KEY_PWD);
}
}
this.init(u);
return u;
}

applicationcontext。xml
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="REQUIRED" />
<tx:method name="drop*" propagation="REQUIRED" />
<tx:method name="userLogin" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事物 -->
<aop:config>
<aop:pointcut id="transActionPointcut" expression="execution(* cn.com.jxzy.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="transActionPointcut" advice-ref="txAdvice" />
</aop:config>

切面aspect
public class UserLoginlogAspect extends BaseDaoImpl<Loginlog, Integer> implements MethodInterceptor {

@Override
public Object invoke(MethodInvocation arg0) throws Throwable {
User user = (User) arg0.proceed();
Object[] arr = arg0.getArguments();
this.addLoginlog((Loginlog) arr[1]);
return user;
}

/**
* 插入用户登陆日志信息
* @param loginlog
*/
private void addLoginlog(Loginlog loginlog) {
this.getHibernateTemplate().save(loginlog);
}
}

就是这个切面插入日志报的错
切面配置aspect
	<!-- 持久层 -->
<bean id="userDao" class="cn.com.jxzy.persist.impl.UserDaoImpl" parent="baseDao"></bean>
<!-- 业务层 -->
<bean id="userService" class="cn.com.jxzy.service.impl.UserServiceImpl" autowire="byName"></bean>
<!-- 用户登陆日志管理 -->
<bean id="userLoginlogAspect" class="cn.com.jxzy.aspect.UserLoginlogAspect" parent="baseDao"></bean>
<!-- 织入 -->
<aop:config>
<aop:pointcut id="userLoginlogPointcut" expression="execution(* cn.com.jxzy.service.impl.UserServiceImpl.userLogin(..))"/>
<aop:advisor advice-ref="userLoginlogAspect" pointcut-ref="userLoginlogPointcut"/>
</aop:config>
...全文
194 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
willxuecn 2015-10-20
  • 打赏
  • 举报
回复
唉 重写个userLoginDao 和userLoginService专门处理登陆就好了,不知道什么原因
心随自在飞 2015-10-20
  • 打赏
  • 举报
回复
可能是编译的问题! 很多时候我也是,新建类,重新敲一遍代码就好了! 楼 主 请 淡 定

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧