配置文件/导入方法
-
创建(自定义,自动扫描,可能为空)
@Configuration
。
-
用注释
@Profile("redis")
。
-
用附加注释
@Import(RedisAutoConfiguration.class)
。
完成!看起来像:
package com.my.package;
import org.springframework.context.annotation.*;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
@Configuration
@Profile("redis")
@Import(RedisAutoConfiguration.class)
// config more here...
class MyRedisConfig {
// ..or here
}
这
将
重新导入
application.yaml
-排除(仅适用于RedicAutoConfig类),
激活“redis”配置文件时
。
不确定这是否比复制&粘贴方法,但听起来完全是什么,配置+导入+配置文件是“专为”设计的!)
如果
@配置
类标记为
@Profile
,所有
@Bean
方法和
@Import
除非一个或多个指定的配置文件处于活动状态,否则将绕过与该类关联的注释