小编d48*_*48b的帖子

Spring 启动缓存不适用于 @PostConstruct 或 @AfterPropertiesSet

当我的应用程序启动时,我尝试用数据初始化我的缓存,但这不起作用。我的代码:

springBoot应用程序

package com.r2b.springcache;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("com.r2b")
@SpringBootApplication
@EnableCaching
public class SpringCacheApplication {

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

    @Bean
    public CacheManager cacheManager() {
        return new ConcurrentMapCacheManager("student");
    }
}
Run Code Online (Sandbox Code Playgroud)

学生

package com.r2b.model;

public class Student {

    String id;
    String name;
    String clz;

    public Student(String id, String name, String clz) {
        super();
        this.id = id;
        this.name = name;
        this.clz = clz;
    }

    public String getId() { …
Run Code Online (Sandbox Code Playgroud)

java spring caching spring-boot spring-cache

2
推荐指数
1
解决办法
2593
查看次数

标签 统计

caching ×1

java ×1

spring ×1

spring-boot ×1

spring-cache ×1