1.1.5、SpringBoot整合其他框架
一、整合Junit
搭建SpringBoot工程
引入starter-test起步依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>编写测试类
添加测试相关注解
@RunWith(SpringRunner.class)
@SpringBootTest(classes = 启动类.class)
备注:添加“启动类.class”是因为测试类没有在对应的启动类包下,如果在对应的包下,无需添加
编写测试方法
二、整合Redis
搭建SpringBoot工程
引入Redis起步依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>配置redis相关属性
# 不配置的话,默认链接到本机redis spring: redis: host: 127.0.0.1 port: 6379 ......注入RedisTemplate模板
@Autowirde private RedisTemplate redisTemplate;编写测试方法,测试
三、整合MyBatis
搭建SpringBoot工程
引入mybatis起步依赖,添加MySQL驱动
编写DataSource和MyBatis相关配置
定义表和实体类
编写dao和mapper文件/纯注解开发
测试
Last updated
Was this helpful?