[英]Spring Boot: ComponentScan vs Declared Bean in an Autoconfigured Jar
[英]Importing spring boot jar into another app without @ComponentScan and Xml Configurations
我正在尋找一種通用/干凈的解決方案,將 spring boot jar 應用程序導入另一個 spring boot 應用程序,而無需執行 @ComponentScan(應用程序的包名稱),無需 xml 配置。
如果我沒有在基礎應用程序中說@Componentscan,@Autowired 不起作用,這是可以理解的。
所以一般來說用 spring boot 編寫庫不是一個理想的方式嗎?
最后,我選擇了 @Import(ApplicationConfiguration),我覺得它很簡潔。
我有一個多級項目結構,所以每個子模塊都創建了一個配置文件來啟動所需的 bean,然后在父模塊中,我使用了 @Import。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.