spring boot使用Ehcache缓存

1.导入坐标


        
            org.springframework.boot
            spring-boot-starter-cache
        

        
            net.sf.ehcache
            ehcache
        

2.  在springboot(.yml)中设置使用Ehcache

spring:
  cache:
    type: ehcache

3.导入Ehcache设置ehcache.xml(自行在网上寻找即可)



    
    
    
    
    

    


4.在springboot启动类中开启注解

@SpringBootApplication
//开启缓存
@EnableCaching
public class Demo1Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
    }

}

5.在所需要开启缓存的上方开启注解即可

@CachePut( value = "smsCode",key = "#tele")
    public String sendCodeToSMS(String tele) {
        return codeUtil.generator(tele);
    }

你可能感兴趣的:(spring,boot,缓存,java)