In my Spring-Boot-App I want to conditionally declare a Bean, depending on (un)loaded spring-profiles.
The conditon:
Profile \"a\" NOT loaded
AND
Unfortunately I don't have a shorter solution for you, but if it is suitable in your case to create the same beans for each profile, you may consider the following approach.
@Configuration
public class MyBeanConfiguration {
@Bean
@Profile("a")
public MyBean myBeanForA() {/*...*/}
@Bean
@Profile("b")
public MyBean myBeanForB() {/*...*/}
@Bean
@ConditionalOnMissingBean(MyBean.class)
public MyBean myBeanForOthers() {/*...*/}
}