1. What is Spring Boot

Spring Boot is a sub-project of Spring open source organization. It is a one-stop solution for Spring components. It mainly simplifies the difficulty of Spring, saves the heavy configuration, and provides various initiators, enabling developers to get started quickly.

2、为什么要用SpringBoot

Rapid development, rapid integration, simplified configuration, embedded service containers

3. Difference between SpringBoot and SpringCloud

SpringBoot is a fast developing Spring framework, SpringCloud is a complete microservice framework, SpringCloud depends on SpringBoot.

4. What are the advantages of SpringBoot

(1) Easy to use, improve development efficiency, provide a faster and simpler development framework for Spring development.

(2) Out of the box, away from tedious configuration.

(3) Provide a series of non-business functions common to large projects; Such as embedded servers, security management, operational data monitoring, health checks, and external configuration

(4) SpringBoot summary is to make coding, configuration, deployment, monitoring become simple, etc

5. What are the core annotations for SpringBoot? Mainly composed of those few notes

The annotation above the boot class is @SpringBootApplication, which is the core annotation of SpringBoot.

@springBootConfiguration: The @Configuration annotation is combined to realize the function of the Configuration file.

@enableAutoConfiguration: Enable or disable the automatic configuration function. Such as: Java as closed automatic configuration data source: @ SpringBootApplication (exclude = {DataSourceAutoConfiguration. Class}).

@ComponentScan:Spring component scanning.

6. What logging frameworks are supported by SpringBoot, and what is the recommended and default logging framework

Springboot supports Java Util Logging, Log4j2, and Logback as Logging frameworks. If you use the Starters launcher, Springboot will use Logback as the default Logging framework. Either logging framework supports exporting configuration files to a console or file

7. Working principle of Springboot Starter

The @SpringBootApplication annotation automatically reads the Spring. factories file in Maven from each starter when Springboot is started. This file configates all the beans in the spring container that need to be created. And automatically configure the bean to be injected into the SpringContext

What’s new with Springboot 2.X and what’s different from 1.X

Springboot2 is based on Spring5 and Jdk8

Configuration changes, parameter names, etc

Many of the lowest versions of springBoot2-related plug-ins are better than before

2. Chinese characters in the X configuration can be read directly without transcoding

CacheManage change

What front-end templates does Springboot support

Thymeleaf, freemarker, JSP, official JSP is not recommended

10. Disadvantages of Springboot

Difficult for people, because do not have to do their own configuration, error is difficult to locate

11, how many ways to run SpringBoot

Package to run with commands or in containers

Run with the Maven/Gradle plugin

Execute the main method directly

12. Springboot needs a separate container to run?

Tomcat/Jetty is built in

13. What are the ways to enable the Springboot feature

Integrate the spring-boot-starter-parent project

Import the spring-boot-Dependencies project dependencies

14, Springboot to achieve hot deployment in several ways

Hot deployment means that you don’t have to re-run the Springboot project, and you can automatically update the operating background code to the running project.

Spring the Loaded. Spring – the boot – devtools.

15. Use of Springboot transactions

Springboot transaction is very simple, the first to use annotations @ EnableTransactionManagement open after the transaction, then on the Service method annotation @ Transactional.

Async Call method asynchronously

The asynchronous invocation master requires the @async annotation on the method to implement the asynchronous invocation. Note: the @enableAsync annotation needs to be added to the class using the asynchronous call @async annotation to take effect

How do I run specific code when Springboot starts

You can implement interfaces ApplicationRunner or CommandLineRunner, both of which are implemented in the same way as providing only a run method.

SpringBoot has several ways to read configuration files

Variables can be bound via @propertyseource, @Value, @Environment, and @ConfiguraitonProperties annotations

19. What is JavaConfig

Spring JavaConfig is a Spring community product introduced in Spring3.0 that provides a pure Java method for configuring the SpringIOC container. So it helps to avoid using XML configuration. The advantages are:

Object-oriented configuration: Because configuration is defined as a class in JavaConfig, you can take full advantage of Java’s object-oriented capabilities. One configuration class can inherit from another, override its @bean methods, and so on.

Reduce or eliminate XML configuration: Externalizing configuration based on dependency injection principles has proven benefits. However, many developers do not want to switch back and forth between XML and Java. JavaConfig provides developers with a pure Java way to configure a Spring container that is similar in concept to XML configuration.

Technically, it is possible to configure the container using only the JavaConfig configuration class, but in practice many people think that mixing JavaConfig and XML is optimal

Type-safe and refactoring friendly: JavaCOnfig provides a type-safe way to configure the Spring container. Thanks to java5.0 support for generics, beans can now be retrieved by type rather than by name, without any casts or string-based look-ups.

Common JavaConfig:

@Configuration: Indicates that the class is a Configuration class.

@ComponentScan: Added the @ComponentScan annotation to the configuration class. By default, this annotation scans all configuration columns in the package in which the class resides, equivalent to context: Component-scan.

@bean: Bean injection, equivalent to before

@enableWebMVC: The MVC equivalent of XML :annotation-driven

ImportResource: equivalent to XML

20. What is the principle of SpringBoot auto-assembly

SpringBootApplication annotates the main configuration class. With this main configuration class, SpringBoot will start with an @enableAutoConfiguration annotation for automatic configuration.

With @enableAutoConfiguration, you can:

(1) Load any possible autowler classes from the META_INF/ spring. factories configuration file.

(2) De-weigh and remove classes carried by the exclude and excludeName attributes.

(3) Filter, return the automatic configuration class that meets the condition (@Conditional).

21, How to understand the SpringBoot configuration load sequence

There are several ways to load configuration in Springboot; Properties files, YAML files, system environment variables, command line arguments, etc

22. What are YAML files

YAML is a human-readable data serialization language. It is usually used for configuration files. Compared to properties files, YAML files are more structured and less confusing if you want to add complex properties to a configuration file. YAML has hierarchical configuration data.

23. What are the advantages of YAML configuration

YAML is now a very popular configuration file format for both the front end and the back end. Advantages are as follows:

Order configuration. In some special scenarios, order configuration is critical

Succinctly, it also supports arrays, whose elements can be primitive data types or objects

YAML also has a disadvantage over properties profiles in that it does not support the @propertyResource annotation to import custom YAML configurations.

24. Whether SpringBoot can be configured with XML

Java rather than XML configuration is recommended for SpringBoot, but XML configuration can also be used for SpringBoot, and an XML configuration can be introduced via the @importResource annotation.

What is the Springboot core configuration file? Bootstrap. properties and application.properties

The bootstrap.properties configuration file may not be easy to encounter purely for Springboot development, but it is often present in conjunction with Spring Cloud, especially when loading some remote configuration files.

Two configuration files for the SpringBoot core:

Bootstrap (.yml or. Properties) : Bootstrap is loaded by the parent interface ApplicationContext before Application. The configuration takes effect during the boot phase of the application context. This file is typically used in SpringCloud configurations. And the BootStrap

Files in cannot be overwritten.

Application (.yml or. Properties) : recorded by ApplicationContext and used for automatic configuration of the Springboot project.

26. What are Spring Profiles

During project development, some configuration files may be different in development, test, or production environments, such as database links, redis configuration, and so on. Spring gives us the Profiles mechanism which gives us the ability to switch back and forth between Profiles.

Spring Profiles allows users to register beans against configuration files (dev, test, PROd, and so on). Springboot makes using configuration files very simple.

27, SpringBoot multi-data source split ideas

Now configure two data sources in the Properties file, create a subcontracted Mapper, read the configuration in Properties using @ConfigurationPropertis, and register it in the corresponding Mapper package using @mapperscan.

How to manage SpringBoot multi-source transactions

(1) Use TransactionManager in @transactionManager to specify the transaction configured in the DatasourceCOnfig.

(2) Using JTA-Atomikos to achieve distributed transaction management

29, How to implement SpringBoot application security

To implement Springboot security, the spring-boot-starter-security dependency is used and a security configuration must be added. It requires very little code. The configuration class must extend WebSecurityConfigurerAdapter and override the method.

30. Compare the pros and cons of Spring Security and Shiro

Because Springboot provides a large number of out-of-the-box starters, including the Security starter, it is much easier to use Spring Security, even if you only need to add a dependency to protect all interfaces. Therefore, Spring Security is usually selected for Springboot projects.

Shiro has the following features compared to SpringSecurity:

SpringSecurity is a heavyweight security management framework; Shrio is a lightweight security management framework.

SpringSecurity is complicated in concept and configuration. Shiro is simple in concept and configuration.

SpringSecurity is powerful, Shiro is simple.

How does SpringBoot solve cross-domain problems

Cross-domain can be solved on the front end with JSONNP, but JSONNP can only send GET requests. Therefore, the backend is recommended to solve cross-domain problems through (CORS: Cross-Origin Resource Sharing). CORS is not unique to SPringBoot. In traditional SSH frameworks, CORS can be used to solve cross-domain problems.

Except that the @Configuration annotation, which was configured in XML, is now available by overriding the addCorsMappings method in the WebMvcConfigurer interface. ,

What is the monitor in SpringBoot

SpringBoot Actuator is one of the important functions in Spring boot framework. The Springboot monitor helps you access the current status of running applications in your production environment. The monitor module exposes a set of REST endpoints that can be accessed directly as HTTP urls to check status.

How to use SpringBoot to implement global exception handling

SpringBoot provides a very useful way for ControllerAdvice to handle exceptions by implementing a ControllerAdvice class that handles exceptions thrown by controllers.

How do I monitor all SpringBoot microservices

Springboot provides a monitoring endpoint to monitor the quality of individual microservices. These endpoints are useful for getting information about applications, such as whether they are started, and whether their components, such as databases, are running properly. One disadvantage, however, is that the application endpoint must be opened separately to understand its state

Or health. In order to deal with this situation the use of moth write external application monitoring systems, such as Promethesu, Graphite, Datadog, etc. Have a webui

How does SpringBoot perform

If the project is large and has many analogies, use @Component instead of @SpringBootApplication to specify the scan scope

Set initial AND maximum JVM memory to be the same at project startup

Set the Springboot built-in server to Undeertow by Tomcat.

36, How to reload Springboot changes without restarting the server, how to hot deploy

Springboot has a DevTools module that helps increase developer productivity.

37. How to implement session sharing in Springboot microservice

In microservices, a complete project is divided into multiple different independent services, which are deployed on independent servers, and their Session physical space is isolated. The common solution is SpringSession+ Redis to achieve Session sharing. All sessions are stored in Redis and all read and write operations are performed

Both are based on Redis operations. SpringSession is implemented based on proxy filters in Spring, making Session synchronization transparent and easy for developers