Created
July 26, 2018 10:26
-
-
Save sunxboy/f24a41c93b51485e22500a95ab910ba0 to your computer and use it in GitHub Desktop.
mybatis junit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mybatis-config.xml | |
<configuration> | |
<mapper> | |
<mapper resource="mybatis-cfg/TaskMapper.xml"/> | |
</mapper> | |
</configuration> | |
#spring-config.xml | |
<context:annotation-config /> | |
<tx:annotation-driven/> | |
<jdbc:embedded-database id="datasource" type="HSQL"> | |
<jdbc:script location="classpath:schema.sql"/> | |
<jdbc:script location="classpath:test-data.sql"/> | |
</jdbc:embedded-database> | |
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> | |
<property name="dataSource" ref="dataSource"/> | |
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/> | |
</bean> | |
<bean id="mapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> | |
<property name="mapperInterface" value="com.skycomm.cpip.connector.manager.mapper.TaskMapper"/> | |
<property name="sqlSessionFactory" ref="sqlSessionFactory"/> | |
</bean> | |
</beans> | |
# java | |
@RunWith(SpringJunit4ClassRunner.class) | |
@ContextConfiguration("classpath:/spring-config.xml") | |
public class TaskMapperTest { | |
@Autowired | |
private SqlSessionFactory sqlSessionFactory; | |
@Test | |
public void shouldGetAllTasks() { | |
try (SqlSesson sqlsession = sqlSessionFactory.openSession()) { | |
TaskMapper mapper = sqlSession.getMapper(TaskMapper.class) | |
List<TaskInfo> tasks = mapper.getAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment