简体   繁体   中英

Conditionally loading an external spring boot autoconfiguration based on loaded profile

I have the following requirements while loading an autoconfiguration (via @EnableAutoConfiguration and spring.factories :

  • Exclude the autoconfiguration based on the current profile
  • Don't modify the imported autoconfigurations (starter jars)

The only options I can think off are:

  • adding a flag property in the autoconfiguration
  • adding a @Profile annotation on the autoconfiguration

But both options require modifying the autoconfiguration starter jars, which I prefer not to.

Is there a way to achieve this?

这全都与@ComponentScan有关,您将需要为2个配置文件进行2个父级自动配置,一个使用@ComponentScan并带有包含您的其他子级自动配置的软件包,另一个用于排除您不需要的自动配置。此配置文件,如果要扫描除此自动配置以外的包括此自动配置的软件包,可以使用excludeFilters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM