@ConditionalonProperty Wie benutzt man zweimal auf derselben Bohne?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: @ConditionalonProperty Wie benutzt man zweimal auf derselben Bohne?

by Anonymous » 02 Apr 2025, 06:13

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?>

Top