我正在使用 Spring Boot 處理一些 Java 專案。我在專案MyAutoConfig的spring.factories檔案中有一個自動配置的類A。
這個組態檔有一些 bean 定義,例如 class Worker。
該專案B使用A的圖書館,像這樣的gradle產出:
implementation project(':project-A')
我可以毫無錯誤地開始專案B。但是當我嘗試在我擁有的主類@Autowired Worker worker中的專案B中使用時@SpringBootConfiguration,它告訴我"expected at least 1 bean which qualifies as autowire candidate",所以我假設 bean 不在背景關系中。
我想知道可能是什么問題?
uj5u.com熱心網友回復:
@SpringBootConfiguration對于自動配置是不夠的。你應該添加@EnableAutoConfiguration. 這將觸發掃描spring.factories檔案并為您完成其余的作業。
或者使用@SpringBootApplication,因為它包含EnableAutoConfiguration在其中。
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/342765.html
