preface



Spring Boot is a set of rapid development framework. With the continuous popularity of micro-service architecture applications, the mastery of Spring Boot development technology has become a required skill for developers. At the same time, Spring Boot’s open source ecological construction capability is very strong, providing many application components, so that Spring Boot has a rich use of third-party open source software.


Based on the above situation, Spring Boot has become a must-have question for interviews at large and medium-sized Internet companies.

This article according to the company some interview question bank combing, will provide the core knowledge to share with you.

This article mainly contains 30 knowledge points, basically can cover the common Spring Boot interview questions.

I hope I can help you in the following interview.

Let’s cut to the chase today!


30 Facts


1. What is Spring Boot?

2. What are the advantages of Spring Boot?

3. SpringBoot boot mode

4. What annotations are used in SpringBoot?

5. What does SpringBoot hot deployment use?

6. What is the difference between hot deployment and hot loading?

7. How to implement SpringBoot packaging?

8. How to optimize SpringBoot performance?

New features in SpringBoot2.0

10. SpringBoot execution process

How to use Spring Boot to implement paging and sorting?

12, What is Swagger? Did you implement it with Spring Boot?

13. What are Spring Profiles?

14. What is Spring Batch?

15. What is a FreeMarker template?

16. How to use Spring Boot to implement exception handling?

Which Starter Maven dependencies do you use?

What is a CSRF attack?

What are WebSockets?

What is AOP?

What is Apache Kafka?

22. How do we monitor all Spring Boot microservices?

What is the difference between Spring Boot, Spring MVC and Spring?

24. What is automatic configuration?

25. What is Spring Boot Stater?

26. Can you give an example that explains more about Staters?

27, What is the easiest way to create a Spring Boot Project?

28. What are the requirements for configuration files?

29. Can you give an example of ReadOnly for transaction management?

What is the best way to publish Spring Boot custom configurations for user applications?


1. What is Spring Boot?

Over the years, Spring has become more complex as new features have been added. Simply visit https://spring.io/projects pages, we’ll see you can use in our application of all the different function of a Spring project.



If we had to start a new Spring project, we had to add build paths or Maven dependencies, configure the application server, and add Spring configuration. So starting a new Spring project takes a lot of effort, because we now have to do everything from scratch.



Spring Boot is the solution to this problem. Spring Boot is already built on top of the existing Spring framework. With Spring boot, we avoided all the boilerplate code and configuration that we had to do before. Therefore, Spring Boot can help us use existing Spring functionality more robustly with less effort.


2. What are the advantages of Spring Boot?



The advantages of Spring Boot include:



Reduced development, testing time and effort.

Using JavaConfig helps you avoid using XML.

Avoid massive Maven imports and versioning conflicts.

Provide advice on developing methods.

Start development quickly by providing default values.

No separate Web server is required. This means you no longer need to start Tomcat, Glassfish, or anything else. Less configuration is required because there is no web.xml file. Simply add the class annotated with @Configuration, then add the method annotated with @Bean, and Spring will automatically load the object and manage it as before.



You can even add @AutoWired to the bean method to make Spring automatically load the required dependencies. Context-based configuration Using these properties, you can deliver the environment you are using to your application: -dspring.profiles. active = {enviorvulnerabilities}. After loading the main application properties file, Spring loads subsequent application properties files in (Application {environment}.properties).


3,SpringBoot Boot mode



The IDE runs the main method of the Application class to run MVN in the root directory of the Springboot Application. Spring-boot :run generates the JAR using MVN install



4,SpringBoot uses those annotations



@ SpringBootApplication @ Component: @ RestController


5,What does SpringBoot hot deployment use?



Spring Loaded

spring-boot-devtools



6,What is the difference between hot deployment and hot loading?



Deployment way

Hot deployment redeploys the project while the server is running. Hot loading reloads the class at run time

Realize the principle of

Hot deployment reloads the entire application directly. Hot loading reloads the class at run time

Usage scenarios

Hot deployment is more about hot loading in production and more about real development



7,How does SpringBoot package?



Profiles are set for different environments in poM files, where the dev environment configuration is activated by default

Then configure the application.properties that need to be included and filtered

Then use Maven’s package command to implement different environment packaging



Eight,How is SpringBoot performance optimized?



Tomcat memory tuning, change files (Catalina.sh), boot part optimization can remove @SpringBootApplication and @ComponentScan annotations to disable automatic component scanning, and then explicitly configure the beans we need


9,SpringBoot2.0 new features




Spring Boot 2 is completely based on java8, which introduces Webflux for HTTP requests. It is based on Spring Webflux, which is a new non-blocking functional Web framework Reactive.

It can be used to build asynchronous, non-blocking, event-driven services that scale well.

Compared with the previous synchronization method, the performance is improved


In db, HikariCP is introduced by default


HikariCP replaces tomcat-pool as the underlying database connection pool. Compared with tomcat-pool, HikariCP has better performance. In short, it improves db access speed.


Redis aspects


Oracle was introduced by default, replacing jedis as the underlying redis link mode,

Also, the underlying database database is based on netty framework, using asynchronous mode to access redis, and if combined with previous Webflux, it can achieve full asynchronous request, also compared with previous Jedis, unifying the access mode of redis and Redis-Cluster. This simplifies the way developers use redis, while also improving access speed


Es in terms of


The default has also been upgraded from es2 support to es5+, es5 has been out for a while, and most people are probably implementing their own es5 docking. Now springboot2 is also supporting es5.


The metrics in


Spring Boot 2 introduced Micrometer to standardize metrics,

Allows developers to better understand and use metrics without worrying about what the docking store is.



10,SpringBoot executes the process?




1) Start the request


2) Collect various conditions and callback interfaces


3) Notification started()


4) Create and prepare the Environment


5) Circular environmentPrepared()


6) Create and initialize ApplicationContext


ContextPrepare (), contextLoaded()


8) Call the Refresh () method of ApplicationContext to complete the final program startup


9) Execute ApplicationRunner and CommandlineRunner notification finished()


End of the 10)




How to use Spring Boot to implement paging and sorting?



Using Spring Boot to implement paging is simple. Using Spring Data-jPA, you can implement pageable

Org. Springframework. Data. Domain. Pageable passed to the repository.



12, What is Swagger?Did you implement it with Spring Boot?



Swagger is widely used in visualization apis, using the Swagger UI to provide an online sandbox for front-end developers. Swagger is a tool, specification, and complete framework implementation for generating visual representations of RESTful Web services. It enables documents to be updated at the same rate as the server.



When defined correctly by Swagger, consumers can understand and interact with remote services with minimal implementation logic. Thus, Swagger takes the guesswork out of invoking the service.



13. What are Spring Profiles?



Spring Profiles allows users to register beans against configuration files (dev, test, PROd, etc.). Therefore, when the application is running in development, only certain beans can be loaded, while in PRODUCTION, certain other beans can be loaded.



Let’s say our requirement is that the Swagger document only works in the QA environment and all other documents are disabled. This can be done using configuration files. Spring Boot makes using configuration files very simple.



14. What is Spring Batch?



Spring Boot Batch provides reusable functions that are important when handling a large number of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and capabilities that enable extremely high volume and high performance batch jobs through optimization and partitioning techniques. Both simple and complex bulk batch jobs can leverage the framework to process significant amounts of information in a highly extensible manner.

15. What is a FreeMarker template?



FreeMarker is a Java-based templating engine that initially focused on dynamic web page generation using MVC software architecture. The main advantage of using Freemarker is the complete separation of the presentation layer and the business layer. Programmers can work with application code, while designers can work with HTML page design. Finally, using Freemarker, you can combine these together to give the final output page.



16. How to use Spring Boot to implement exception handling?



Spring provides a very useful way to handle exceptions using ControllerAdvice. We handle all exceptions thrown by the controller class by implementing a ControlerAdvice class.



Which Starter Maven dependencies do you use?



The following dependencies are used

spring-boot-starter-activemq


spring-boot-starter-security



spring-boot-starter-web



This helps to add fewer dependencies and reduce version conflicts.



What is a CSRF attack?



CSRF stands for cross-site request forgery. This is an attack that forces an end user to perform unwanted actions on a currently authenticated Web application. CSRF attacks specifically target state-change requests, not data theft, because the attacker cannot see the response to forged requests.



What are WebSockets?



WebSocket is a computer communication protocol that provides a full-duplex communication channel over a single TCP connection.

  • WebSocket is bidirectional – a WebSocket client or server can initiate message sending.

  • WebSocket is full-duplex – client and server communication is independent of each other.



  • Single TCP connection – The initial connection uses HTTP, then this connection is upgraded to a socket based connection. This single connection is then used for all future communications

  • Light – WebSocket message data exchange is much lighter than HTTP.



What is AOP?



In software development, functionality that spans multiple points in an application is called a crossover problem. These crossover issues are different from the main business logic of the application. Thus, separating these crosscutting concerns from business logic is where aspect-oriented programming (AOP) comes in.



What is Apache Kafka?



Apache Kafka is a distributed publish-subscribe messaging system.



It is an extensible, fault-tolerant publish-subscribe messaging system that enables us to build distributed applications. This is an Apache top-level project. Kafka is suitable for offline and online messaging consumption.



22. How do we monitor all Spring Boot microservices?



SpringBoot provides monitor endpoints to monitor metrics for 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 functioning properly.



However, one of the major disadvantages or difficulties of using monitors is that we have to open the knowledge points of the application separately to understand its state or health. Imagine a microservice involving 50 applications, where the administrator would have to hit the execution terminals for all 50 applications.



What is the difference between Spring Boot, Spring MVC and Spring?



1, Spring



The most important feature of Spring is dependency injection. All SpringModules are either dependency injection or IOC inversion of control.



When we use DI or IOC properly, we can develop loosely-coupled applications. Unit testing for loosely coupled applications can be done easily.



2, Spring MVC



Spring MVC provides a discrete approach to developing Web applications. Using simple concepts such as DispatcherSeret, MoudlAndView, and ViewResolver, developing Web applications becomes much easier.



3, SpringBoot



The problem with Spring and SpringMVC is that a lot of parameters need to be configured.



Spring Boot addresses this problem with an automatic configuration and startup TAB. To build product-ready applications faster, Spring Boot provides some non-functional features.


24. What is automatic configuration?



The problem with Spring and SpringMVC is that a lot of parameters need to be configured.



Can we bring more intelligence? Can we automatically configure some Beans when an MVC JAR is added to the application?


Spring looks at the configuration of existing applications (frameworks available on your CLASSPATH). Based on this, Spring Boot provides the basic configuration needed to configure applications and frameworks. This is automatic configuration.



25. What is Spring Boot Stater?



Initiators are a convenient set of dependency descriptors that can be placed in their own programs. You can get the Spring and related technologies you need in one stop shop, without relying on descriptors to search through sample code and copy-paste the load.

For example, if you want to use Sping and JPA to access a database, all you need is for your project to include spring-boot-starter-data-jPA dependencies and you’ll be fine.



26. Can you give an example that explains more about Staters?



Let’s consider an example of Stater -Spring Boot Stater Web.

If you want to develop a Web application or one that exposes REST services. Spring Boot Start Web is preferred. Let’s use Spring Initializr to create a quick project for Spring Boot Start Web.

Spring Boot Start Web dependencies




The screenshots below are different dependencies added to our application




Dependencies can be divided into:

  • Spring-core, beans, Context, AOP

  • Web MVC – (Spring MVC)

  • Jackson – for JSON Binding

  • Validation – Hibernate,Validation API

  • Enbedded Servlet Container – Tomcat

  • Logging – logback,slf4j

Any classic Web application will use all of these dependencies. The Spring Boot Starter Web prepackaged these dependencies.

As a developer, I don’t have to worry about these dependencies and their compatible versions anymore.


27, What is the easiest way to create a Spring Boot Project?



Spring Initializr is a great tool to start Spring Boot Projects.



As shown in the image above, we need to do the following steps:


  • Log in to Spring Initializr and choose as follows:

  • Select com. In28minutes. Springboot for groups

  • Select Studet-Services as the component

  • Select the dependencies below

  • Web

  • Actuator

  • DevTools

  • Click on the raw GenerateProject

  • Import the project into Eclipse. File – Import – Existing Maven project


28. What are the requirements for configuration files?



Enterprise application development is complex, and you need a mix of environments:

  • Dev

  • QA

  • Stage

  • Production In each environment, you want different application configurations.

Configuration files facilitate different application configurations in different environments.

Spring and Spring Boot provide functionality that you can specify.

  • What is the configuration of different environments in different configuration files?

  • Set up active profiles for a defined environment.

Spring Boot selects the configuration of the application based on the active configuration file set in the specific environment.



29. Can you give an example of ReadOnly for transaction management?



When you read from the database, you want to set the user or other description in the transaction to read-only mode so that Hebernate doesn’t have to double-check for entity changes. It’s very efficient.


What is the best way to publish Spring Boot custom configurations for user applications?



The problem with @Value is that you can assign your configuration values via the application. A better approach is to take a focused approach.

You can define a configuration component using @ConfigurationProperties.




You can configure parameters in application.properties.

basic.value: true basic.message: Dynamic Message basic.number: 100

Well, everyone, that’s the end of this article!



If there are any mistakes in this article, please comment, appreciate!


The last


See here, you really good, give you a thumbs up, you give me a thumbs up. Hey hey


More than 400 pages of PDF documents of 1000 Java interview questions from many companies in 2019, as well as hundreds of pages of PDF of Java core knowledge points. ​Copy the code
Please follow my official account to get it: just reply "interview" or "PDF".Copy the code



I am timothy

A flood of moral integrity, a awe-inspiring, upright Java programmer