In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "Spring Boot 2.x basic tutorial on how to configure the application of metadata", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "Spring Boot 2.x basic tutorial on how to configure the application of metadata"!
When using Spring Boot to develop applications, have you found such a situation: custom properties have a high background, mouse up, there is a Cannot resolve configuration property configuration warning.
If you are not bored with this warning and want to remove it, you can remove it by setting it:
However, my advice is not to remove it, because this warning can be used to distinguish between your custom configuration and framework configuration by highlighting, allowing you to quickly tell which ones are custom.
If you really want to get rid of it, it is not recommended to use the method mentioned above, but to do it by perfecting the configuration of metadata. So, let's talk about the application of configuration metadata in detail today!
What is configuration metadata?
We might as well open a created Spring Boot project, take a look at its Spring Boot dependency package, and find a json file in the following figure:
What is wrong here is the configured metadata information. Have you found that the values of these name are very familiar? Is description familiar with it, too? Yes, these are the metadata information for our commonly used native configuration of Spring Boot.
Now you know what configuration metadata can do? It can help IDE to complete the display of configuration associations and configuration tips.
The reason why our custom configuration will report a warning, but also no prompt message, it is because there is no configuration file for this metadata!
Automatic generation of configuration metadata
Now that we know the principle, let's try to use configuration metadata!
Step 1: create a configuration class and define a custom configuration
@ Data@Configuration@ConfigurationProperties (prefix = "com.didispace") public class DidiProperties {/ * this is a test configuration * / private String from;}
Step 2: add dependencies to pom.xml that automatically generate configuration metadata
Org.springframework.boot spring-boot-configuration-processor
Step 3: mvn install under this project.
At this point, we can find the metadata file in the project target directory:
At the same time, when we try to write this custom configuration item in the configuration file, we can see that the compiler gives associations and hints:
And, after writing the configuration, there is no highlight warning!
At this point, I believe you have a deeper understanding of "how to configure the application of metadata in the basic Spring Boot 2.x tutorial". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.