How to Bind Recursive Configuration Structures in Micronaut? #11872
Unanswered
alexey-lapin
asked this question in
Q&A
Replies: 2 comments
-
|
No, we calculate the properties path at the compilation time. The only way would be using Micronaut Serialization and having the beans annotated with |
Beta Was this translation helpful? Give feedback.
0 replies
-
Solution : Using @ConfigurationProperties with explicit nested classesThis works for simple recursive structures (one level of self-reference). import io.micronaut.context.annotation.ConfigurationProperties;
import java.util.List;
@ConfigurationProperties("app")
public class AppConfig {
private List<Condition> conditions;
public List<Condition> getConditions() {
return conditions;
}
public void setConditions(List<Condition> conditions) {
this.conditions = conditions;
}
@ConfigurationProperties
public static class Condition {
private String type;
private Condition not; // Self-reference
private List<Condition> and; // Self-reference in list
private List<Condition> or; // Self-reference in list
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Condition getNot() {
return not;
}
public void setNot(Condition not) {
this.not = not;
}
public List<Condition> getAnd() {
return and;
}
public void setAnd(List<Condition> and) {
this.and = and;
}
public List<Condition> getOr() {
return or;
}
public void setOr(List<Condition> or) {
this.or = or;
}
}
}application.yml: app:
conditions:
- type: type1
- and:
- type: type2
- or:
- type: type3
- type: type4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I am wondering if it is possible to bind arbitrarily nested recursive structures in Micronaut.
In Spring it is possible to do so:
Is there an equivalent or alternative way to achieve this in Micronaut?
Beta Was this translation helpful? Give feedback.
All reactions