foreword
At present, we have completed the implementation of the department management and employee management function interface. In the Alibaba Cloud OSS tool class, we will set 4 parameters, which are the cloud service domain name, cloud service ID and password, and the bucket for file storage. There will be the following Problem: If the parameter configuration is scattered and the parameters change, it needs to be modified corresponding to all positions that use the changed parameters. So define parameters in the SpringBoot configuration file application.properties.
specific solution
- Set the value of the parameter in the configuration file
- Use annotation @Value("${key in configuration file}")
- @Value is usually used for attribute injection of external configuration
Key codes in configuration files
Parameter usage in java project
summary
- If you need to use some technologies and services in a specific project in the future, you can configure the value of the required parameter in the configuration file to manage the parameters uniformly.