我已经配置了事物为什么还是报错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>
...全文
142 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
willxuecn 2015-10-20
唉 重写个userLoginDao 和userLoginService专门处理登陆就好了,不知道什么原因
回复
心随自在飞 2015-10-20
可能是编译的问题! 很多时候我也是,新建类,重新敲一遍代码就好了! 楼 主 请 淡 定
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-20 10:18
社区公告
暂无公告