스프링

 

applicationContext.xml

	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<constructor-arg name="dataSource" ref="dataSource" />
	</bean>
	
	<tx:annotation-driven transaction-manager="transactionManager"/>

 

 

 

 class MyBatisTest 

 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/*.xml"})
public class MyBatisTest {

 

	@SuppressWarnings("unused")
	@Test
	@Transactional
	public void insert() {
		SqlSession session=null;
		try{
			session =sqlSessionFactory.openSession();
			User user =new User("snajgi79", "password" , "sanjigi" , "sangigi@slipp.net");
			session.insert("UserMapper.create", user); 
			session.commit();
			session.close();
			session=sqlSessionFactory.openSession();
		    User actual =session.selectOne("UserMapper.findById", user.getUserId());
			assertThat(actual.getUserId(), is(user.getUserId()));
			
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			if(session!=null)session.close();
		}
	}
	
	
	

 

 

 

 

 

 

 

spring

 

about author

PHRASE

Level 60  머나먼나라

친구와 적은 있어야 한다. 친구는 충고를, 적은 경고를 해 준다. -소크라테스

댓글 ( 4)

댓글 남기기

작성