Spring Java Configuration之@EnableAutoConfiguration__Java

來源:互聯網
上載者:User

官網上的解釋是這樣的:

Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined.

Auto-configuration tries to be as intelligent as possible and will back-away as you define more of your own configuration. You can always manuallyexclude() anyconfiguration that you never want to apply (use excludeName() if you don'thave access to them). You can also exclude them via thespring.autoconfigure.exclude property. Auto-configuration is always appliedafter user-defined beans have been registered.

The package of the class that is annotated with @EnableAutoConfiguration has specific significance and is often used as a 'default'. For example, it will be usedwhen scanning for@Entity classes. It is generally recommended that you place@EnableAutoConfiguration in a root package so that all sub-packages and classescan be searched.

Auto-configuration classes are regular Spring Configuration beans. They are located using the SpringFactoriesLoader mechanism (keyed against this class).Generally auto-configuration beans are@Conditional beans (mostoften using @ConditionalOnClass and@ConditionalOnMissingBean annotations).

首先,顧名思義,@EnableAutoConguration是和自動化配置相關的東西。

官網的第一段話主要是說,Spring應用內容相關的自動化配置,嘗試去猜測和配置你需要的bean。這些被自動化配置的類通常在classpath路徑下,或者是你自己定義的bean。

第二段話主要是說,你可以使用exclude來排除那些你不想被自動化配置的類。

第三段是講:被@AutoConfiguration註解的類所在的包有著特殊的意義,他們通常被認為是預設的包,並對其及下屬的包進行掃描。

第四段前半句是說,被自動設定的類通常是在@Configuration裡面配置的類。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.