CacheProperties类使用了@ConfigurationProperties注解,可以从配置文件加载配置参数值赋类里各个成员变量,@EnableConfigurationProperties
根据字面意思判断就是将使用@ConfigurationProperties注解的类注入到Spring IOC容器里,交给Spring管理
@EnableConfigurationProperties(value = CacheProperties.class)
–相当于–>
@Component@ConfigurationProperties(prefix = “spring.cache”)
```java
//开启属性绑定配置功能,CacheProperties类只用了 @ConfigurationProperties注解,没有用@Component将该类注册到容器里,这样无法获得配置信息转化成的bean
//@EnableConfigurationProperties注解,根据意思-开启配置属性,就是使@ConfigurationProperties注解生效,把使用该注解的类进行一次注入
@EnableConfigurationProperties(value = CacheProperties.class)
@Configuration //配置类
@EnableCaching //开启注解
public class MyCacheConfig {
@Bean
RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties){
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer
@ConfigurationProperties(
prefix = "spring.cache"
)
public class CacheProperties {
private CacheType type;
private List cacheNames = new ArrayList();
private final CacheProperties.Caffeine caffeine = new CacheProperties.Caffeine();
private final CacheProperties.Couchbase couchbase = new CacheProperties.Couchbase();
private final CacheProperties.EhCache ehcache = new CacheProperties.EhCache();
private final CacheProperties.Infinispan infinispan = new CacheProperties.Infinispan();
private final CacheProperties.JCache jcache = new CacheProperties.JCache();
private final CacheProperties.Redis redis = new CacheProperties.Redis();
public CacheProperties() {
}



