Home > Java > javaTutorial > body text

How to define configuration file information in java

PHPz
Release: 2023-04-29 22:58:05
forward
1506 people have browsed it

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;
}
Copy after login

Inject this bean when using

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

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!