Interview must master the 15 "Spring Boot high-frequency interview questions."

Doing Java development, no one dares importance of Spring Boot underestimated , now out of the interview, no matter how small the company or project, to be with you said something about Spring Boot, said something about micro-services, will not? Not used? Sorry, not to us!

Give us today finishing the 15 high-frequency Spring Boot interview questions, hoping to help the junior partner just out of school and ready to find new jobs junior partner.

First, what is Spring Boot?


Traditional SSM / SSH framework of portfolio allocation tedious bloated, different projects have a lot of repetition, template-based configuration, severely reducing the efficiency of development Java engineers and Spring Boot can easily create a Spring-based, can run independently, production-level applications program. Through the Spring family and some third-party libraries offer Starter series of automated configuration, enabling developers to quickly build a Spring-based applications.

Spring Boot allow increasingly bloated Java code and return to simplicity. When used in conjunction Spring Cloud use, it can also play a greater power.

Two, Spring Boot What are the characteristics?


Spring Boot mainly has the following characteristics:

(A) providing a faster, wider entry for the Spring development experience.

(B), out of the box, away from complicated configuration.

(Iii), provides a series of large-scale projects of common non-business functions, such as: embedded servers, security management, operational data monitoring, health checks and externalize configuration.

(Four), absolutely no code generation and does not require XML configuration.

Three, Spring Boot the starter in the end what is?


First of all, this is nothing new technologies Starter point, basically been implemented based on Spring function. First, it provides an automated configuration class, usually named XXXAutoConfiguration, in this configuration class to determine whether a configuration entry into force of (the condition Spring notes that originally there is) annotated by the conditions, then it will also provide a series of default configuration also allows developers to customize the configuration according to the actual situation, then inject these configuration properties injected in through the security type attribute, inject new property will replace out default properties. Because of this, many third-party framework, we only need to introduce rely on can be used directly.

Of course, developers can also customize Starter, Custom Starter can refer to: a freehand line and Boot in the Starter Spring, decryption automated configuration of black magic! .

Four, spring-boot-starter-parent what's the use?


We all know that the new project to create a Spring Boot default are all parent and this parent is spring-boot-starter-parent, spring-boot-starter-parent have the following main functions:

(A) defines the Java compiler version 1.8.

(B), encoded using UTF-8 format.

(Three), inherited from the spring-boot-dependencies, this dependence is defined inside version, it is precisely because of this dependency inherited, so we do not need to write the version number when writing dependence.

(4) As to the configuration of the packaging operations.

(E), automated resource filter.

(Vi), the plug-in configuration automation.

(Seven), and for resources application.properties application.yml filtering, including through the profile defined configuration files for different environments, such as application-dev.properties and application-dev.yml.

On this issue, the reader can refer to: Do ​​you really understand the Spring Boot project parent do?

V. What are the advantages of the YAML configuration?


YAML can now be regarded as a very popular configuration file format, whether it is front-end or back-end, you can see the YAML configuration. So YAML configuration and traditional properties configured in the end what advantage compared to what?

(A), the configuration ordered, under some special scenes, the configuration ordered is critical

(B) supporting an array, the array elements can be basic data types may be subject

(C), simple

Compared properties profile, YAML also has a drawback, it is not supported @PropertySource comment YAML import custom configuration.

About YAML configuration, if you are not familiar with, you can refer to: yaml in Spring Boot Configuration Introduction

6, how to solve cross-domain problems in Spring Boot?


Cross-domain can be solved through the front JSONP, but JSONP can only send a GET request can not be sent to other types of requests, in RESTful style applications, it is very sad, so we recommend in the back-end through (CORS, Cross-origin resource sharing) to solve cross-domain problems. This solution is not unique to Spring Boot, in the traditional SSM framework, cross-domain problem can be solved by CORS, CORS configuration before but we are in the XML file, now it is to solve cross-domain by @CrossOrigin comment problem. About CORS, little friends can refer to: solve cross-domain problem by CORS Spring Boot

Seven Spring Security and Shiro compare their advantages and disadvantages?


Since the Spring Boot official offers plenty of convenient out of the box Starter, including Spring Security of Starter, making it easier to use Spring Security in Spring Boot in, or even just need to add a dependency can protect all interfaces, so, if it is Spring Boot project, usually selected Spring Security. Of course this is only a suggestion of the combination, technically simple, no matter how they are combined, are no problem. Shiro and compared with Spring Security, mainly has the following characteristics:

(A), Spring Security is a heavyweight security management framework; Shiro is a lightweight security management framework

(B), Spring Security concept complex, cumbersome configuration; Shiro simple in concept, easy configuration

(Three), Spring Security is powerful; simple function Shiro

Eight, how to implement the micro-service session to share?

In the micro service, a complete project is split into multiple different independent service, each service independently deployed on different servers, each session is physically isolated from the space, but often we need sharing session between different micro-services, a common solution is to be achieved Spring session + Redis session sharing. The session of the unity of all micro-services saved on Redis, when the individual micro-service session related read and write operations are to operate session on Redis. This realization of the session sharing, Spring Session in Spring proxy filter based on the realization that the synchronization session for developers is clear, very simple. session sharing we can refer to: Spring Boot relies get a sharing session, there is no easier than this scheme up!

Nine, Spring Boot realize how hot deployment?

Spring Boot hot deployment is very easy to achieve, you can rely on the introduction of devtools, so when compiling a file changes, Spring Boot will automatically restart. In Eclipse, the user presses the save button will automatically compile and then restart the Spring Boot, IDEA due is automatically saved, not compile time saved automatically, so developers need to press Ctrl + F9 to compile, after completion of the translation, the project will automatically restart.

If you just change the page template, Java classes has not changed, then you can not restart the Spring Boot, using LiveReload plug-in you can easily hot deployment.

Ten, how to achieve Spring Boot scheduled task?

Timing is also a common task demands, Spring Boot for regular tasks in support mainly from the Spring framework.

Use regular tasks in Spring Boot mainly in two different ways, one is using Spring in @Scheduled notes, the other is to use third-party frameworks Quartz.

Use in Spring @Scheduled way to achieve mainly through @Scheduled comment.

Quartz use, according to the embodiment of Quartz, and Trigger definitions to Job.

About timed task this one, you can refer to: Spring Boot in two ways to achieve timing tasks!

XI, before and after the end of the separation, how to maintain the interface documentation?

Separating the front and rear ends of the development of increasingly popular, in most cases, we are doing before and after the end of the separation developed by Spring Boot, front and rear end there will be separate interface documentation, or front and rear end will be deep into the wrangling in. A stupid way is to use the word or md to maintain the interface documentation, but the efficiency is too low, the interface for a change, all of the documents had to change hands. In Spring Boot, this problem is a common solution is to Swagger, Swagger we can use to quickly generate a web site interface documentation, once the interface changes, the document will automatically update all development engineers to access this online site can get the latest interface documentation, very convenient. Swagger on usage, we can refer to: SpringBoot integration Swagger2, no longer have to maintain the interface documentation!

XII What is Spring Data?

Spring Data is a sub-project of the Spring. To simplify database access, support for NoSQL and relational data storage. Its main goal is to make access to the database becomes quick and easy. Spring Data has the following characteristics:

(A), SpringData project support NoSQL store:

(Two), MongoDB (a document database)

(Three), Neo4j (graph database)

(IV), Redis (key / value storage)

(Five), Hbase (column family databases)

SpringData project supported relational data storage technology:

(A), JDBC

(Two), JPA

Spring Data Jpa committed to reducing the amount of development data access layer (DAO) of Developers only thing to do is to declare an interface persistence layer, the other to the Spring Data JPA to help you complete! Spring Data JPA specification by the name of the method to determine the name of the method according compliant What kind of logic needs to achieve.

Thirteen, Spring Boot whether you can use the XML configuration?

Spring Boot recommended configuration instead of Java XML configuration, but Spring Boot can also use XML configuration can be introduced through an XML configuration @ImportResource comment.

Fourteen, Spring Boot labeled the jar and the jar ordinary What is the difference?

Spring Boot packaged into the jar final project is an executable jar, this jar can be run directly by java -jar xxx.jar command, this jar can not be relied upon as an ordinary jar other items, even if can not rely on the use of which the type.

Spring Boot the jar and can not be dependent on other projects, mainly different structures and ordinary jar of him. Ordinary jar package, unpacked directly is the package name, the bag is our code, and after the Spring Boot packaged into an executable jar unzip in \ BOOT-INF \ classes directory is under our code, and therefore can not be directly references. If I have to reference, you can increase the pom.xml file configuration, Spring Boot project packaged into two jar, an executable, a reference.

Fifth, what is the difference bootstrap.properties and application.properties?

Spring Boot simply do develop, may not be easy to meet bootstrap.properties profile, but when combined Spring Cloud, this configuration will often encountered, especially in some of the right time to load remote configuration file.

bootstrap.properties before application.properties loading configuration to take effect at boot application context. Generally we will use it in Spring Cloud Config or Nacos in. bootstrap.properties is Spring ApplicationContext parent class loader, this class starts before loading application.properties of ApplicatonContext.

Of course, the foregoing description of the properties may be modified to yaml.

Well, we stop here, welcome to leave a message about your little friends have encountered the Spring Boot face questions!


Reproduced in: https: //juejin.im/post/5d09df686fb9a07ef63fe180

Guess you like

Origin blog.csdn.net/weixin_33709609/article/details/93180680
Recommended