码迷,mamicode.com
首页 > 编程语言 > 详细

spring junit jpa transaction

时间:2014-08-25 23:03:35      阅读:512      评论:0      收藏:0      [点我收藏+]

标签:java   io   for   ar   cti   log   sp   on   ef   

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

标签:java   io   for   ar   cti   log   sp   on   ef   

原文地址:http://my.oschina.net/fengshuzi/blog/306512

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!