簡體   English   中英

為什么要在Spring Boot中使用@PropertySource時需要指定@Configuration?

[英]Why do you need to specify @Configuration when you want to use @PropertySource in Spring Boot?

我知道當您想為 ApplicationContext 添加@Bean 時,您會使用@Configuration。 但是為什么要在 Spring Boot 中使用@PropertySource 時需要指定@Configuration 呢?

來自@PropertySource的 API 文檔:

注釋提供了一種方便的聲明機制,用於將PropertySource添加到 Spring 的環境中。 @Configuration類一起使用。

因此,可以推斷,如果我們使用@PropertySource將由 Spring 容器管理,Spring 將注冊一個org.springframework.core.env.PropertySource bean。 並且需要@Configuation來聲明 Spring bean。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM