1. 程式人生 > 其它 >SpringBoot啟動類上加ComponentScan出現springbootapplication already applies given @ComponentScan

SpringBoot啟動類上加ComponentScan出現springbootapplication already applies given @ComponentScan

技術標籤:【報錯收集】spring bootcomponentScanjava

@[email protected][email protected][email protected],其中掃描包的範圍為啟動類所在包和子包,不包括第三方的jar包。如果我們需要掃描通過maven依賴新增的jar,怎麼處理?

SpringBootApplication原始碼裡面,有:

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackages"
) String[] scanBasePackages() default {};

所以解決的方法很簡單:
在這裡插入圖片描述
如此即可:

@SpringBootApplication(scanBasePackages = {"com.xx"})