我们接下来就自定义将数据保存为json格式
我们先来看源码CacheAutoConfiguration里面的@EnableConfigurationProperties(CacheProperties.class)(将所有的属性都绑定到这里面),我们的CacheAutoConfiguration源码还有如下的配置可以导入CacheConfigurations缓存的自动配置类
/**
* {@link ImportSelector} to add {@link CacheType} configuration classes.
*/
static class CacheConfigurationImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
CacheType[] types = CacheType.values();
String[] imports = new String[types.length];
for (int i = 0; i < types.length; i++) {
imports[i] = CacheConfigurations.getConfigurationClass(types[i]);
}
return imports;
}
}
CacheConfigurations源码里面我们就可以导入redis相关的自动配置类RedisCacheConfiguration
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
总结:CacheAutoConfiguration帮我们导入了org.springframework.boot.autoconfigure.cache;RedisCacheConfiguration源代码如下
class RedisCacheConfiguration {
@Bean
RedisCacheManager cacheManager(CacheProperties cacheProperties, CacheManagerCustomizers cacheManagerCustomizers,
ObjectProvider<org.springframework.data.