2

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.

  • @beckyang: the linked question deals with excluding the whole autoconfiguration. As stated in the question, I need the beans it provides except one. Do you imply that the only way to do that is to disable the third-party autoconfiguration completely, and then... how do I get all the useful beans? – occasionalcharter Feb 15 '17 at 15:52
  • I think you can disable the autoconfiguration, specify another `@ComponentScan` with `excludeFilters`. Please @refer http://stackoverflow.com/a/33309782 – Beck Yang Feb 15 '17 at 16:11
  • The autoconfiguration that you suggest to disable has a method marked with `@Bean` that registers a few filters. If I understand correctly, when this autoconfiguration is disabled, the registration won't work as well, and I need to replicate it in my code. I'd like to avoid that. – occasionalcharter Feb 15 '17 at 16:18
  • Can you please reconsider marking it as duplicate? I've rephrased the title and the question to highlight the difference from the linked question. – occasionalcharter Feb 16 '17 at 11:15
  • I don't have permission to retract the mark now. What's the third-party spring boot starter? Maybe the `@RestController` can be disabled by another way. – Beck Yang Feb 16 '17 at 15:22
  • It's `com.atlassian.connect:atlassian-connect-spring-boot-starter:1.3.0`. – occasionalcharter Feb 16 '17 at 17:13
  • The `@RestController AtlassianConnectErrorController` is a `ErrorController`. Maybe `@ControllerAdvice` is what you need. @see http://stackoverflow.com/a/33003627 – Beck Yang Feb 17 '17 at 15:13

0 Answers0