开发者社区 问答 正文

Spring 配置了事物 层是 oshop.service.下面的类

@Test
    @Transactional
    @Rollback(false)
    public void insertSystemRole() {
        Role role = new Role();
        role.setName("超级管理员");
        role.setDescription("最高权限管理员");
        role.setDisabled(false);
        // role.setId(UUID.randomUUID().toString());
        role.setOrderIndex(0);
        role.setSystemRole(true);

        Set<Power> powers = new HashSet<Power>();
        Power p = new Power();
        p.setRole(role);
        p.setPowerKey(PowerKey.ALL);
        powers.add(p);
        role.setPowers(powers);
        roleService.save(role);
        
        Admin admin = new Admin();
        admin.setDisabled(false);
        admin.setOrderIndex(0);
        admin.setRole(role);
        admin.setUserName("admin");
        admin.setPassword(PasswordEncryptor.encryptPassword("123456"));
        adminService.save(admin);
    }
上面是Spring JUNIT 测试类里面的一个方法。发现代码到roleServcie.save() 以后,sessionFactory就关闭了。后面的admin 就进不去了。

下面是Console输出:

信息: Began transaction (1): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@fd12614]; rollback [false]
Hibernate: 
    insert 
    into
        Role
        (disabled, orderIndex, description, name, systemRole, id) 
    values
        (?, ?, ?, ?, ?, ?)
Hibernate: 
    insert 
    into
        Power
        (disabled, orderIndex, powerKey, role_id, id) 
    values
        (?, ?, ?, ?, ?)
Hibernate: 
    insert 
    into
        Admin
        (disabled, orderIndex, password, role_id, userName, id) 
    values
        (?, ?, ?, ?, ?, ?)
2011-3-3 23:32:30 org.springframework.test.context.transaction.TransactionalTestExecutionListener endTransaction
信息: Committed transaction after test execution for test context [[TestContext@fe14de0 testClass = RoleServiceTest, locations = array<String>['classpath:/applicationContext.xml'], testInstance = oshop.test.RoleServiceTest@10bfb545, testMethod = insertSystemRole@RoleServiceTest, testException = [null]]]
2011-3-3 23:32:30 org.springframework.context.support.AbstractApplicationContext doClose
信息: Closing org.springframework.context.support.GenericApplicationContext@3e110003: startup date [Thu Mar 03 23:32:26 CST 2011]; root of context hierarchy
2011-3-3 23:32:30 org.logicalcobwebs.proxool.ConnectionPool shutdown
信息: Shutting down 'oshop' pool immediately [Shutdown Hook]
2011-3-3 23:32:30 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@649a8a68: defining beans [sessionFactory,transactionManager,allServiceTransactionAdvice,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,adminServiceImpl,roleServiceImpl,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,adminDaoImpl,baseDaoImpl,roleDaoImpl]; root of factory hierarchy
3384 [Thread-7] INFO  org.hibernate.impl.SessionFactoryImpl  - closing
3387 [Thread-7] WARN  org.hibernate.connection.ProxoolConnectionProvider  - Exception occured when closing the Proxool pool
org.logicalcobwebs.proxool.ProxoolException: Couldn't find a pool called 'oshop'. Known pools are: 
    at org.logicalcobwebs.proxool.ConnectionPoolManager.getConnectionPool(ConnectionPoolMa

展开
收起
a123456678 2016-03-12 17:38:12 2505 分享 版权
1 条回答
写回答
取消 提交回答
  • 更换成C3P0连接池就可以测试了。看来是因为PROXOOL交给Spring管理的不是很好。

    2019-07-17 19:01:17
    赞同 展开评论