解决方案 »

  1.   

    这个是 CommonDao.javapackage com.ssmm.dao;import javax.annotation.Resource;import org.apache.ibatis.session.SqlSessionFactory;
    import org.mybatis.spring.support.SqlSessionDaoSupport;
    import org.springframework.stereotype.Component;
    import org.springframework.stereotype.Service;public class CommonDao extends SqlSessionDaoSupport {
    @Resource
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
    super.setSqlSessionFactory(sqlSessionFactory);
    }
    }
      

  2.   

    你为什么要在Controller里面这么做呢?
      

  3.   

    去掉<tx:advice>与<aop:config>,在CommonDao类上加入@Transactional注解.
      

  4.   

    把事务aop配置放到spring mvc的配置文件里, 外面的访问不到mvc里扫描到的bean, 但mvc的配置可以访问外面的bean。你试下
      

  5.   


    [com.ssmm.dao.UserMapper.selectByPrimaryKey]==>  Preparing: select id, username, password, age from user where id = ? 
    [com.ssmm.dao.UserMapper.selectByPrimaryKey]==> Parameters: 91(Integer)
    [com.ssmm.dao.UserMapper.selectByPrimaryKey]<==      Total: 1
    [org.mybatis.spring.SqlSessionUtils]Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4]
    684
    [org.mybatis.spring.SqlSessionUtils]Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4] from current transaction
    [com.ssmm.dao.UserMapper.insert]==>  Preparing: insert into user (id, username, password, age) values (?, ?, ?, ?) 
    [com.ssmm.dao.UserMapper.insert]==> Parameters: 236(Integer), 6(String), 6(String), 6(Integer)
    [com.ssmm.dao.UserMapper.insert]<==    Updates: 1
    [org.mybatis.spring.SqlSessionUtils]Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4]
    [org.mybatis.spring.SqlSessionUtils]Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4] from current transaction
    [com.ssmm.dao.UserMapper.deleteByPrimaryKey]==>  Preparing: delete from user where id = ? 
    [com.ssmm.dao.UserMapper.deleteByPrimaryKey]==> Parameters: 91(Integer)
    [com.ssmm.dao.UserMapper.deleteByPrimaryKey]<==    Updates: 1
    [org.mybatis.spring.SqlSessionUtils]Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4]
    [org.springframework.jdbc.datasource.DataSourceTransactionManager]Participating transaction failed - ing existing transaction as rollback-only
    [org.springframework.jdbc.datasource.DataSourceTransactionManager]Setting JDBC transaction [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2eb9eee9] rollback-only
    [org.mybatis.spring.SqlSessionUtils]Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4]
    [org.mybatis.spring.SqlSessionUtils]Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4ccd32f4]
    [org.springframework.jdbc.datasource.DataSourceTransactionManager]Initiating transaction rollback
    [org.springframework.jdbc.datasource.DataSourceTransactionManager]Rolling back JDBC transaction on Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2eb9eee9]
    [org.springframework.jdbc.datasource.DataSourceTransactionManager]Releasing JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@2eb9eee9] after transaction
    [org.springframework.jdbc.datasource.DataSourceUtils]Returning JDBC Connection to DataSource
    [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]Resolving exception from handler [public com.ssmm.model.User com.ssmm.controller.UserController.showOneUser(int)]: java.lang.RuntimeException
    [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]Resolving exception from handler [public com.ssmm.model.User com.ssmm.controller.UserController.showOneUser(int)]: java.lang.RuntimeException
    [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]Resolving exception from handler [public com.ssmm.model.User com.ssmm.controller.UserController.showOneUser(int)]: java.lang.RuntimeException
    [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]Resolving exception from handler [public com.ssmm.model.User com.ssmm.controller.UserController.showOneUser(int)]: java.lang.RuntimeException
    [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]Resolving to default view 'error' for exception of type [java.lang.RuntimeException]
    [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]Exposing Exception as model attribute 'exception'
    [org.springframework.web.servlet.DispatcherServlet]Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'error'; model is {exception=java.lang.RuntimeException}
    java.lang.RuntimeExceptionInitiating transaction rollback已经回滚太感谢了。。
    我心中还有个疑惑,我继承的SqlSessionDaoSupport 和我 注入的 <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> 有什么本质上的区别吗,请大神指教。
      

  6.   


    Initiating transaction rollback已经回滚太感谢了。我心中还有个疑惑,我继承的SqlSessionDaoSupport 和我 注入的 <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> 有什么本质上的区别吗,请大神再指教下
      

  7.   

    不行,没有起作用,6楼的哥们的方法解决了,可能是这个原理
    http://5880861.blog.51cto.com/5870861/1544168还是万分感谢你关注我的问题,谢谢
      

  8.   

    不行,没有起作用,6楼的哥们的方法解决了,可能是这个原理
    http://5880861.blog.51cto.com/5870861/1544168还是万分感谢你关注我的问题,谢谢你可以把CommonDao作为Controller的属性使用@Autowire来注入.
      

  9.   


    Initiating transaction rollback已经回滚太感谢了。我心中还有个疑惑,我继承的SqlSessionDaoSupport 和我 注入的 <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> 有什么本质上的区别吗,请大神再指教下
    如果是单例的,那么都是在spring容器启动的时候初始化, 没什么本质区别
      

  10.   

    结贴啦,,不烦啦。。谢谢各位。。
    http://bbs.csdn.net/topics/390904063
    我的新问题,有兴趣的大大,帮忙看看。