In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the interview questions of the Java Spring Boot framework?" in the operation of the actual case, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The configuration file format of Spring Boot.
Application.properties or application.yml, the main difference between them is the different writing format.
1.properties:
Springboot.user.name = testname
2.yml:
Springboot:
User:
Name: testname
In addition, the properties of the .properties format file are unordered, and the properties of the .yml format file are ordered, but it does not support the @ PropertySource annotation import configuration.
II. The core notes of Spring Boot
The above annotation of the startup class is @ SpringBootApplication, which is also the core annotation of SpringBoot. The main combination includes the following three annotations:
@ SpringBootConfiguration: combines @ Configuration annotations to implement the function of configuration files.
@ EnableAutoConfiguration: enable the auto-configuration feature, or disable an auto-configuration option, such as disabling the data source auto-configuration feature:
@ SpringBootApplication (exclude = {DataSourceAutoConfiguration.class})
@ ComponentScan:Spring component scan.
Third, the way to enable the Spring Boot feature
1. Inherit spring-boot-starter-parent project
two。 Import spring-boot-dependencies project dependencies
Fourth, the way to run Spring Boot
1. Directly execute the main method to run
two。 Run with the Maven / Gradle plug-in
3. Pack it into a jar package and run it directly through the java-jar command
5. How Spring Boot reads the configuration
Spring Boot can bind variables through @ PropertySource,@Value,@Environment,@ConfigurationProperties.
VI. Monitor in Spring Boot
Spring Boot actuator is one of the important functions in the Spring startup framework. The Spring Boot Monitor helps you access the current status of running applications in a production environment. For example, what bean was created, the mapping in the controller, CPU usage, and so on. You can then automatically collect and audit health status (health) and indicators (metric) into your application.
7. The principle of automatic configuration of Spring Boot?
Add @ SpringBootApplication or @ EnableAutoConfiguration to the main method of the Spring program. Automatically go to maven to read the spring.factories file in each starter, which is configured with all the bean that needs to be created in the spring container.
Spring Boot scans the JAR package that the project depends on at startup to find the JAR that contains the spring.factories file
Load AutoConfigure classes based on spring.factories configuration
Automatically configure and inject Bean into Spring Context according to the conditions of @ Conditional annotation
VIII. Spring-boot-maven-plugin
Spring-boot-maven-plugin provides commands to package or run applications like jar.
Run: run your Spring Boot application.
Repackage: repackage your jar package or war package to make it executable
Start and stop: manage the lifecycle of Spring Boot applications, or for integration testing.
Build-info: generates construction information that can be used by the executor.
Use the configuration file to configure the configuration of a specific environment through Spring Boot
For example, there are now two configuration files, application-dev.properties and application-prod.properties. The configuration of the application-prod.properties configuration file can be loaded by using spring.profiles.active=prod in application.properties.
How to disable a specific autoconfiguration class
@ SpringBootApplication (exclude= {Order.class})
@ EnableAutoConfiguration (exclude= {DataSourceAutoConfiguration.class})
@ EnableAutoConfiguration (excludeName= {Foo.class})
11. Loading of Spring Boot factory mode
A factory loading mechanism (Factory Loading Mechanism) is used internally in Spring Framework. This mechanism is done using SpringFactoriesLoader, and SpringFactoriesLoader uses the loadFactories method to load and instantiate factories from the spring.factories files in the META-INF directory, which are found in the jar package in classpath.
This is the end of the content of "what are the interview questions for the Java Spring Boot framework". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.