@ConfigurationProperties 是 Spring Framework 中的一個注解,用于自動將配置文件中的屬性值注入到 Java 對象中。
使用 @ConfigurationProperties 注解時,我們需要為目標類添加該注解,并指定要映射的屬性前綴。然后,Spring 會自動將配置文件中以該前綴開頭的屬性值注入到該類的相應屬性中,屬性名需要與配置文件中的屬性名一致。
以下是一個簡單的 @ConfigurationProperties 示例:
```
@Component
@ConfigurationProperties(prefix = "my.component")
public class MyComponent {
private String name;
private int age;
private boolean enabled;
// getters and setters
}
```
在上述示例中,我們使用 @ConfigurationProperties 注解將名為 "my.component" 的配置屬性值注入到了 MyComponent 的成員變量中,包括 name、age 和 enabled 三個屬性。
需要注意的是,在使用 @ConfigurationProperties 時,我們需要在配置文件中為目標屬性設置相應的值,例如:
```
my.component.name=Tom
my.component.age=28
my.component.enabled=true
```
在上述示例中,我們設置了名為 "my.component" 的屬性前綴,并為其下 name、age 和 enabled 三個屬性分別設置了相應的值。
總之,@ConfigurationProperties 是 Spring Framework 中用于自動將配置文件中的屬性值注入到 Java 對象中的注解。通過該注解,我們可以更加方便地對應用程序進行配置,提高應用程序的可維護性和可擴展性。
- 環境配置
- 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服務