In my Spring Boot application, I depend on some third-party spring boot starter. The beans that it provides are useful except for one, which I would like to prevent from instantiating. However, none of the usual solutions apply here, because I cannot modify the sources of the library, so I cannot insert a @Condition
on the bean or a @ComponentScan
on its auto-configuration class.
Excluding the whole third-party auto-configuration is also not a solution, because I need the rest of the beans it provides; the auto-configuration also registers some filters in a method annotated with @Bean
.
The bean in question is a @RestController
that adds a @RequestMapping
on an /error
path, but I'd rather use the conventional way of placing my own error template.
Perhaps I could define my own controller to override this, but first I'd love to know if there is a way to solve the more general problem of excluding certain beans from instantiating --- I have a feeling that I'll need it once more down the road.