spring boot使用缓存-爱代码爱编程
1.导入依赖
<!--缓存依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
2.在启动类上开启使用缓存的注解
@SpringBootApplication
//开启缓存
@EnableCaching
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
}
3.在需要使用缓存的上方加上缓存注解@Cacheable