Page 1 of 1

@ConditionalonProperty Wie benutzt man zweimal auf derselben Bohne?

Posted: 02 Apr 2025, 06:13
by Anonymous
Gibt es eine Möglichkeit, @ConditionalonProperty zweimal für dieselbe Bean zu verwenden?

Code: Select all

@Bean
@ConditionalOnProperty(prefix = "app.config.inside", name = "prop", havingValue = "a")
@ConditionalOnProperty(prefix = "app.config.outside", name = "prop", havingValue = "a") //??
public SomeBean beanForPropA() {
return new SomeBean1();
}

@Bean
@ConditionalOnProperty(prefix = "app.config.inside", name = "prop", havingValue = "b")
@ConditionalOnProperty(prefix = "app.config.outside", name = "prop", havingValue = "b") //how to add second?
public SomeBean beanForPropB() {
return new SomeBean2();
}
< /code>
und application.yaml < /p>
app:
config:
inside:
prop: a
outside:
prop: b
Ich möchte die Beans registrieren, wenn eine der Innen-/Außenprops "A" oder "B" als Wert hat. Derzeit erlaubt Spring nicht zwei @ConditionalonProperty auf derselben Bean. Also irgendwelche Ideen, wie man das macht?>