❝
From SSH to SpringMVC, with the development of Spring, it is easier to develop SpringBoot. SpringBoot has become a must for Java programmers.
❞
1. What is SpringBoot?
Spring Boot makes it easy to create standalone, production-level Spring-based applications that you can “run.” Most Spring Boot applications require minimal Spring configuration.
2.SpringBoot features?
- Create a stand-alone Spring application
- Embed directly into Tomcat, Jetty, or Undertow (no need to deploy WAR file)
- Provide hardened “starter” dependencies to simplify build configurations
- Automatically configure Spring and 3rd Party libraries whenever possible
- Provides production-ready functionality, such as metrics, health checks, and externalized configuration
- There is no code generation and no XML configuration required
3. How to quickly build a SpringBoot project?
- Using the Web UI. http://start.spring.io
- Use through Spring Tool Suite.
- Used through IntelliJ IDEA.
- Use the Spring Boot CLI.
4.SpringBoot boot class annotations? What annotations does it consist of?
@SpringBootApplication
- @springBootConfiguration: The @Configuration annotation is combined to realize the function of the Configuration file.
- @enableAutoConfiguration: Enable or disable the automatic configuration function.
- @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
- @ComponentScan:Spring component scanning
5. What is YAML?
YAML (/ˈjæməl/, ending like camel camel) is a readable format for data serialization. YAML references many other languages, including C, Python, and Perl. It’s more structured.
6. Which configuration file formats does SpringBoot support?
1.properties
java.xiaokaxiu.name = xiaoka
Copy the code
2.yml
java:
xiaokaxiu:
name: xiaoka
Copy the code
7.SpringBoot boot mode?
-
The main method
-
Command line java-jar way
-
mvn/gradle
8.SpringBoot needs a separate container to run?
No, Tomcat/Jetty is built in.
9.SpringBoot configuration path?
- Command line arguments
- Java: JNDI properties in comp/env
- JVM System Properties
- Operating system environment variables
- Randomly generated attributes prefixed with random.* (they can be referenced when setting other attributes, such as ${random.long})
- Properties or appliaction.yml file outside the application
- Application. properties or appliaction.yml file packaged within the application
- Annotated PropertySource via @propertysource
- The default attribute
Tips: This list is sorted by priority, meaning that any property set in a high-priority property source overrides the same property set in a low-priority property source.
10. Application. The properties and application. Yml file location can be put on? Priority?
-
External, in the /config subdirectory relative to the application run directory.
-
External, in the directory where the application is running.
-
Built-in, in the config package.
-
Built-in, in the Classpath root.
The list is sorted by priority, with higher priority overwriting lower priority.
Of course we can specify the location of the file to load the configuration file ourselves.
Java - jar xiaoka. Jar - spring. Config. The location = / home/application. The ymlCopy the code
11.SpringBoot automatic configuration principle?
@ EnableAutoConfiguration automatic configuration (open) the annotations introduced AutoConfigurationImportSelector, methods of this class will scan all exist the meta-inf/spring. Factories jars.
12.SpringBoot hot deployment mode?
-
spring-boot-devtools
-
Spring Loaded
-
Jrebel
-
Template hot deployment
13.“bootstrap.yml“ 和“application.yml“?
Bootstrap. yml takes precedence over application.yml
14. How does SpringBoot change the port number?
In the yml:
server :
port : 8888
Copy the code
properties:
server.port = 8888
Copy the code
Command 1:
Java-jar xiaoka.jar -- server.port=8888Copy the code
Command 2:
java - Dserver.port=8888 -jar xiaoka.jar
Copy the code
15. How can I enable the SpringBoot feature?
- Inherits the spring-boot-starter-parent project
- Import the spring-boot-Dependencies project dependencies
16. How is SpringBoot compatible with Spring projects?
In the startup class add:
@ImportResource(locations = {“classpath:spring.xml”})
17.SpringBoot configuration monitoring?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Copy the code
18. Which endpoint to visit for Bean assembly report information?
/ beans endpoint
19. Which endpoint is closed for application access?
/shutdown
This endpoint is disabled by default. If enabled, the following Settings are required.
endpoints:
shutdown:
enabled: true
Copy the code
Or the properties format is ok.
20. Which endpoint is visited to view published application information?
/info
21. How many combined annotations for the requested access?
@PatchMapping
@PostMapping
@GetMapping
@PutMapping
@DeleteMapping
22. Starter?
Understood as a combination of dependencies, the starter includes one or a set of functional-dependent dependencies, avoiding the hassle of having to rely on them and conflicting packages. Greatly improved the development efficiency.
There is a default value for the configuration, and if we configure it ourselves, the default value will be overridden.
23. Mybatis SpringBoot integration?
mybatis-spring-boot-starter
24. What are SpringProfiles?
Generally speaking, we go from development to production, through development (dev), test, and launch (PROD). We use different configurations at different times. Spring Profiles allows users to register beans against configuration files (dev, test, PROd, etc.). They allow us to choose what configuration to use and when.
25. Configuration files for different environments?
It can be application-{profile}.properties/yml, but the default is to launch the main configuration file application.properties. Generally our different environment configuration is as follows.
application.properties
: Primary configuration fileapplication-dev.properties
: Development environment configuration fileapplication-test.properties
: Test environment configuration fileapplication.prop-properties
: configuration file of the production environment
26. How do I activate an environment configuration?
Let’s say we activate the development environment.
Yml:
spring:
profiles:
active: dev
Copy the code
properties:
spring.profiles.active=dev
Copy the code
The command line:
Java - jar xiaoka - v1.0. Jar -- - spring. Profiles. The active = devCopy the code
27. Annotate test cases?
@SpringBootTest
SpringBoot exception handling notes?
@ControllerAdvice
@ExceptionHandler
29. What is the difference between SpringBoot 1.x and 2.x? ……
- SpringBoot 2 is based on Spring5 and JDK8, Spring 1x uses a lower version.
- Configuration changes, parameter names, etc.
- Many of the lowest versions of springBoot2-related plug-ins are higher than before
- 2. Chinese characters in the x configuration can be read directly without transcoding
- The change of the physical
- The change of the CacheManager
30.SpringBoot reads configuration related annotations.
- @PropertySource
- @Value
- @Environment
- @ConfigurationProperties
Reference:
-
SpringBoot In Action (4th Edition)
-
Spring Boot Programming Ideas
-
Spring Boot 2.x
-
https://spring.io/projects/spring-boot
-
Baidu encyclopedia