`@EnableConfigurationProperties` 是 Spring Boot 框架中的一個注解,用于將 `@ConfigurationProperties` 注解標記的類引入到 Spring 容器中,并啟用該注解的類所提供的配置屬性。
使用 `@EnableConfigurationProperties` 注解時,需要指定被掃描的配置類,將其引入到應用程序上下文中。一旦被引入,我們就可以直接在其他組件中使用這些配置屬性了,而不需要手動實例化配置類,并逐個讀取屬性值。
下面是一個使用 `@EnableConfigurationProperties` 注解的示例:
```java
@SpringBootApplication
@EnableConfigurationProperties(MyConfig.class)
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
```
在這個示例中,我們在 `MyApp` 類上使用了 `@EnableConfigurationProperties` 注解,并將 `MyConfig` 類作為參數傳入。這樣,在應用程序啟動時,Spring 就會自動掃描和加載 `MyConfig` 中的配置屬性,并將其注入到其他需要使用這些配置屬性的組件中。
值得注意的是,`@EnableConfigurationProperties` 注解只能掃描并啟用使用了 `@ConfigurationProperties` 注解標記的類,并將其引入到 Spring 容器中。如果想要使用非 `@ConfigurationProperties` 注解標記的配置類,需要使用 `@Import` 注解或 XML 配置文件進行引入。
總之,`@EnableConfigurationProperties` 是 Spring Boot 框架中的一個注解,用于將使用 `@ConfigurationProperties` 注解標記的配置類引入到 Spring 容器中,并啟用該注解的類所提供的配置屬性。使用該注解時需要指定被掃描的配置類,將其引入到應用程序上下文中,以便其他組件可以使用其中的配置屬性。
- 環境配置
- window怎么配置java環境變量?
- Java基礎語法
- Java中的數據類型
- Java中的JSONObject
- Java高級特性
- Maven
- jib-maven-plugin
- 什么是Spring Boot 的 parent pom?
- maven中各個生命周期的含義
- Spring Boot
- maven與spring boot 的關系
- 配置文件
- application-properties配置文件
- Spring Boot 的啟動
- spring boot項目如何啟動?
- 列舉一下Spring Boot的啟動過程
- SpringApplication.run方法
- Spring Boot 啟動時有哪些接口?
- CommandLineRunner
- Spring Boot 的常用注解
- 系統注解
- 表格:系統注解
- @Override
- @Deprecated
- @SuppressWarnnings
- 使用在類名上的注解
- 表格:使用在類名上的注解
- @RestController
- @Controller
- @Service
- @Repository
- @Component
- @Configuration
- @Resource
- @Autowired
- @RequestMapping
- @PostMapping
- @GetMapping
- @Transactional
- @Qualifier
- 使用在方法上的注解
- 表格:使用在方法上的注解
- @RequestBody
- @PathVariable
- @Bean
- @ResponseBody
- @PreAuthorize
- 其他常用注解
- 表格:其他常用注解
- @EnableAutoConfiguration
- @SpringBootApplication
- @EnableScheduling
- @EnableAsync
- @ComponentScan
- @Aspec
- @ControllerAdvice
- @ExceptionHandler
- @Value
- @ConfigurationProperties
- @EnableConfigurationProperties
- @MapperScan
- Validator驗證的常用注解
- spring IoC容器
- Spring IoC容器依賴注入實現方式
- MyBatis
- paginationInterceptor
- @TableName
- @TableId
- @Param
- UrlBasedCorsConfigurationSource
- Lombok
- @Data
- @Slf4j
- @EqualsAndHashCode
- @Accessors
- 支付系統
- 1. 初始化mysql數據庫流程
- 2. 初始化redis數據庫的流程
- 3. 初始化rabbitmq服務