首页 > 代码库 > spring junit jpa transaction
spring junit jpa transaction
package com.fengshu.gotian.applicationImpl; import java.util.List; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.test.context.transaction.TransactionalTestExecutionListener; import org.springframework.transaction.annotation.Transactional; import com.fengshu.gotian.application.UserApplication; import com.fengshu.gotian.core.User; @Transactional @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath*:META-INF/spring/ApplicationContext.xml") @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class }) public class UserApplicationImplTest extends AbstractJUnit4SpringContextTests { private Logger logger = Logger.getLogger(this.getClass()); @Resource(name = "userApplication") private UserApplication userApplication; @Test public void testSpring() { logger.info("test begin"); List<User> users = userApplication.find("from User"); for (User user : users) { userApplication.delete(user); } } }
spring junit jpa transaction
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。