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();
}
}
댓글 ( 4)
댓글 남기기