[英]Why do you need to specify @Configuration when you want to use @PropertySource in Spring Boot?
I know you use @Configuration when you want to add @Bean for ApplicationContext.我知道当您想为 ApplicationContext 添加@Bean 时,您会使用@Configuration。 But why do you need to specify @Configuration when you want to use @PropertySource in Spring Boot?
但是为什么要在 Spring Boot 中使用@PropertySource 时需要指定@Configuration 呢?
From the API documentaion of @PropertySource
:来自
@PropertySource
的 API 文档:
Annotation providing a convenient and declarative mechanism for adding a
PropertySource
to Spring's Environment.注释提供了一种方便的声明机制,用于将
PropertySource
添加到 Spring 的环境中。 To be used in conjunction with@Configuration
classes.与
@Configuration
类一起使用。
So, it can be deduced that Spring will register a org.springframework.core.env.PropertySource
bean if we use @PropertySource
which will be managed by the Spring container.因此,可以推断,如果我们使用
@PropertySource
将由 Spring 容器管理,Spring 将注册一个org.springframework.core.env.PropertySource
bean。 And @Configuation
is needed for declaring Spring beans.并且需要
@Configuation
来声明 Spring bean。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.