In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how the annotations and configuration files are loaded in Springboot, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Common annotations and underlying implementation of Springboot
1. @ SpringBootApplication: this annotation identifies a SpringBoot project, which is actually a combination of three other annotations, namely:
@ SpringBootConfiguration: as you can see from the source code, apart from the meta-annotation, there is actually only one @ Configuration, which turns the class into a configuration class, indicating that the startup class is also a configuration class.
@ EnableAutoConfiguration: to enable automatic configuration, import a Selector into the Spring container to load the automatic configuration classes defined in SpringFactories under ClassPath, and automatically load these as configuration Bean
It consists of @ AutoConfigurationPackage and @ Import, which means that the classes in the package can be automatically scanned into the spring container; using import imports a component into the Spring container, scanning and loading all the packages and subpackages of the main configuration class into the Spring container
When Springboot starts, it obtains the values specified by EnableAutoConfiguration from the META-INF/spring.factories under the classpath, and imports these values into the container as an automatic configuration class. The automatic configuration class takes effect and helps us with automatic configuration. In the past, we need to configure our own things, automatic configuration classes have been done for us.
@ ComponentScan: identifies the scan path. Since the actual scan path is not configured by default, the SpringBoot scan path is the current directory where the startup class is located.
2. @ Bean annotation: used to define Bean, similar to the tag in XML. When Spring starts, it parses the method annotated with @ Bean, takes the name of the method as beanName, and gets the bean object by executing the method.
3, @ Controller, @ Service, @ ResponseBody, @ Autowired
Loading order of configuration files in Springboot
Priority from high to low, high-priority configurations cover low-priority configurations, and all configurations form complementary configurations
1. Command line parameters. All configurations can be specified on the startup command line
2. Java system attributes (System.getProperties)
3. Operating system environment variables
4. Application- {profile} .properties or .yml configuration files outside the jar package; you can make configuration files by:
-- spring.config.location=/bdl/application.properties
5. Configuration files inside the jar package
6. @ Configuration @ PropertySource on the annotation class
On the Springboot comments and configuration file loading order is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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: 282
*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.