Finishing 15 Spring Boot high-frequency interview questions, watching in person tyrants!

Reprinted: https://mp.weixin.qq.com/s/fj-DeDfGcIAs8jQbs6bbPA

What is the face of tyrants? In that interview, god stop killing the Buddha kill the Buddha, adopted piecemeal, to face the interviewer ashamed strange enough! Song Ge hope this can become a stepping stone on the way you face the tyrant!

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!

Today, Song Ge gave you put together 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.

  • 1. 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.

  • 2.Spring Boot What are the characteristics?

Spring Boot mainly has the following characteristics:

  1. Provide a faster, wider entry for the Spring development experience.

  2. Out of the box, away from complicated configuration.

  3. It 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.

  4. Absolutely no code generation and does not require XML configuration.

  • What 3.Spring Boot the starter in the end 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, Starter can custom reference: freehand line and a Boot the Starter Spring, decryption automated configuration of black magic! .

  • 4.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:

  1. It defines the Java compiler version 1.8.

  2. Encoded in UTF-8 format.

  3. 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. Packed perform configuration operations.

  5. Automated resource filter.

  6. Automated plugin configuration.

  7. And resources for application.properties application.yml filtered through a profile comprising a defined profile different environments, e.g. 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?

  • What are the advantages 5.YAML configured?

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?

  1. Configuration ordered in some special scenes, the configuration ordered is critical

  2. Support arrays, the array elements can be basic data types may be subject

  3. concise

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 Configuration Introduction of Spring Boot

  • 6.Spring Boot How to solve cross-domain problems?

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

  • 7. 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:

  1. Spring Security is a heavyweight security management framework; Shiro is a lightweight security management framework

  2. Spring Security concept complex, cumbersome configuration; Shiro concept is simple, easy configuration

  3. Spring Security is powerful; simple function Shiro

  • 8. How to implement 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: the Spring session to get the Boot dependent on a shared, there is no easier than this scheme up!

  • How 9.Spring Boot achieve 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.

  • 10.Spring Boot timing of how to achieve the 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: the Spring Boot in two ways to achieve timing tasks!

  • 11. The front and rear 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!

  • 12. What is the 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:

  1. SpringData project support NoSQL store:

  2. MongoDB (a document database)

  3. Neo4j (graph database)

  4. Redis (key / value storage)

  5. Hbase (column family databases)

SpringData project supported relational data storage technology:

  1. JDBC

  2. 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.

  • 13.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.

  • 14.Spring Boot labeled the jar and the jar ordinary What is the difference?

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

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 decompression in is our code, and therefore can not be directly referenced in the directory. If I have to reference, you can increase the pom.xml file configuration, Spring Boot project packaged into two jar, an executable, a reference.BOOT-INFclasses

  • What is the difference 15.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.

Guess you like

Origin www.cnblogs.com/blogtech/p/11104113.html