Home  >  Article  >  Java  >  How to define configuration file information in java

How to define configuration file information in java

PHPz
PHPzforward
2023-04-29 22:58:051498browse

Sometimes we put some variables into the yml configuration file for unified management

For example

How to define configuration file information in java

Use @ConfigurationProperties Instead of @Value

Use method

Define the entity of the corresponding field

@Data
// 指定前缀
@ConfigurationProperties(prefix = "developer")
@Component
public class DeveloperProperty {
    private String name;
    private String website;
    private String qq;
    private String phoneNumber;
}

Inject this bean when using

@RestController
@RequiredArgsConstructor
public class PropertyController {
 
    final DeveloperProperty developerProperty;
 
    @GetMapping("/property")
    public Object index() {
       return developerProperty.getName();
    }
}

The above is the detailed content of How to define configuration file information in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete