环境识别
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.type.AnnotatedTypeMetadata; /** * 环境识别 */ public class EnvironmentJudge implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String environment = context.getEnvironment().getProperty("environment"); if ("qa".equals(environment) || "prd".equals(environment)) { return true; } return false; } }使用
@Component @Conditional(EnvironmentJudge.class) public class Config { @PostConstruct private void test() { System.out.println("注册进来了....."); } }
标签:springboot,springframework,environment,context,import,注解,public,Condition From: https://www.cnblogs.com/lockyluo/p/17160625.html