Spring-boot junit类读取config配置文件的注解

@SpringBootApplication
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

/*@ContextConfiguration(locations = {"classpath:spring.xml","classpath:spring-mybatis.xml"})*/

Spring-boot junit类读取config配置文件的注解

可以看到,对spring-boot项目进行单元测试是件容易的事儿,需要添加spring-boot-starter-test依赖,然后 使用@RunWith和@SpringBootTest或@SpringApplicationConfiguration(1.4.0过期)注解,然后引入自己要测试的bean,调用指定方法进行测试即可。


源代码参考:https://github.com/xujijun/my-spring-boot