I am creating a bean conditionally in my configuration
@Configuration
@EnableAutoConfiguration
@ComponentScan("com.acme.foo.bar")
public class ApplicationConfiguration {
@Bean
@Conditional(ShouldCreateBean.class)
public MyBean myBean() {
return new MyBean();
}
}
I have a rest controller that only should get created if MyBean
is created
@RestController
@RequestMapping("endpoint")
@ConditionalOnBean(MyBean.class)
public class ArmController {}
Unfortunately, the rest controller does not get created. It seems that the conditional on the controller is executed before my bean is created.
Is there a way to create the controller after MyBean
is created? Some sort of ordering in conditionals?