Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

java - ConfigurationProperties load depends on value

Here's my yaml file, and I want to load my properties depends on activation value.

emp:
 activate: a
 a: 
  param1: value1
  param2: value2
 b:
  param1: value1
  param2: value2

I want to do if activate value is 'a' then load 'a'.

on my source code, AppConfig

@Getter @Setter
@Configuration
@ConfigurationProperties @RequiredArgsConstructor
public class AppConfig {
 @NestedConfigurationProperty
 private final EmpConfig empConfig;
}

my EmpConfig

@Configuration
@ConfigurationProperties(prefix = "emp")
public class EmpConfig {
private String activate;
private Emp a;
private Emp b;

public Emp getEmpConfig(){
    if(activate.equals("a"))
        return a;
    return b;
}

@Getter
@Setter
public static class Emp {
    private String param1;
    private String param2;
}
}

But those code got bean creation error. Is there any nice method to resolve this problem?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...