Spring Boot中使用缓存
在程序中可以使用缓存的技术来节省对数据库的开销。Spring Boot对缓存提供了很好的支持,我们几乎不用做过多的配置即可使用各种缓存实现。这里主要介绍平日里个人接触较多的Ehcache和Redis缓存实现。 准备工作 可根据 Spring-Boot中使用Mybatis.html 搭建一个Spring Boot项目,然后yml中配置日志输出级别以观察SQL的执行情况: 1 2 3 4 5 logging: level: com: springboot: mapper: debug 其中 com.spring.mapper 为MyBatis的Mapper接口路径。 然后编写如下测试方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @RunWith (SpringJUnit4ClassRunner.class) @SpringBootTest (classes = Application.class) public class ApplicationTest { @Autowired private StudentService studentService; @Test public void test () throws Exception { Student student1 = this .studentService