文章詳情頁
java - Spring Boot中@EnableAutoConfiguration和@ComponengScan有什么區別?
瀏覽:135日期:2023-12-12 13:47:47
問題描述
現在的新版spring boot中@SpringBootApplication已經等價于@Configuration, @ComponentScan, @EnableConfiguration。請問@EnableAutoConfiguration和@ComponengScan之間有什么區別?既然@EnableAutoConfiguration可以自動掃描路徑下面的所有bean,那么@ComponentScan似乎就沒有存在的必要了?
問題解答
回答1:1.@EnableAutoConfiguration 主要是用來開啟自動配置是掃描jar包下,配置了META-INF/spring.factories里面的類和針對當前包以及子包下的自定義組件的(也就是歸spring管理的)2.@ComponengScan是用來配置自定義組件的(也就是歸spring管理的),可以指定base路徑orBaseClass
如果要加載的類不在@EnableAutoConfiguration下不會被加載,而且@ComponentScan為spring-context包下的類,是已經存在N久的用于在<context:component-scan>
回答2:@ComponentScan 可以掃描你引入的jar里面的package
標簽:
java
相關文章:
1. docker-machine添加一個已有的docker主機問題2. angular.js - angularjs的自定義過濾器如何給文字加顏色?3. angular.js使用$resource服務把數據存入mongodb的問題。4. 關于docker下的nginx壓力測試5. 為什么我ping不通我的docker容器呢???6. docker安裝后出現Cannot connect to the Docker daemon.7. nignx - docker內nginx 80端口被占用8. docker - 如何修改運行中容器的配置9. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題10. docker鏡像push報錯
排行榜
