What is a face bully? Is in the interview, god block to kill god Buddha block to kill Buddha, see recruit open recruit, face to the interviewer ashamed of his own tourefied! Songo hopes this article will be a stepping stone to your future!

Do Java development, no one dare to underestimate the importance of Spring Boot, now go out to interview, no matter how small the company or project, will talk to you about Spring Boot, talk about micro services, will not? Never used? Sorry, it’s not suitable for us.

Spring Boot Interview questions: Spring Boot Interview questions: Spring Boot Interview questions: Spring Boot Interview questions

  • 1. What is Spring Boot?

The traditional SSM/SSH framework combination configuration is cumbersome and has many repetitive, template-based configurations for different projects, which seriously reduces the development efficiency of Java engineers. Spring Boot can easily create spring-based, independently run, production-grade applications. Providing a series of automatically configured starters for the Spring family and some third-party libraries enables developers to quickly build spring-based applications.

Spring Boot brings simplicity back to increasingly bloated Java code. When used with The Spring Cloud, it can be even more powerful.

  • 2. What are the features of Spring Boot?

Spring Boot has the following features:

  1. Provides a faster, broader entry experience for Spring development.
  2. Out of the box, avoid cumbersome configuration.
  3. Provides a number of non-business features common to large projects, such as embedded servers, security management, operational data monitoring, health checks, and external configuration.
  4. There is absolutely no code generation, and no XML configuration is required.
  • 3. What is starter in Spring Boot?

First, the Starter isn’t a new technology point, and it basically builds on Spring’s existing features. First, it provides an automated configuration class, commonly called XXXAutoConfiguration, in which conditional annotations are used to determine whether a configuration is valid (conditional annotations are native to Spring), and then it provides a set of default configurations. It also allows developers to customize the configuration as needed and then inject these configuration properties through type-safe property injection, which replaces the default properties. Because of this, many third-party frameworks can be used directly by importing dependencies.

Of course, developers can also customize the Starter, the custom Starter can refer to: bare hand lift a Spring Boot Starter, decryption automatic configuration black magic! .

  • 4. Spring-boot-starter -parent

Spring-boot-starter -parent: spring-boot-starter-parent: spring-boot-starter-parent: spring-boot-starter-parent: spring-boot-starter

  1. The Java compiled version is defined as 1.8.
  2. Encoding in UTF-8 format.
  3. < span style = “box-sizing: border-box; color: RGB (74, 74, 74); line-height: 22px; font-size: 14px! Important; word-break: inherit! Important;”
  4. Perform the configuration of the packaging operation.
  5. Automated resource filtering.
  6. Automated plug-in configuration.
  7. Resource filtering for application.properties and application.yml, including configuration files for different environments defined by profiles, For example, application-dev.properties and application-dev.yml.

Do you really understand parent in the Spring Boot project?

  • 5. What are the advantages of YAML configuration?

YAML is now a very popular configuration file format, and you can see YAML configurations on both the front and back ends. What are the advantages of a YAML configuration over a traditional Properties configuration?

  1. Order configuration. In some special scenarios, order configuration is critical
  2. Supports arrays, whose elements can be primitive data types or objects
  3. concise

Another disadvantage of YAML compared to properties profiles is that the @propertysource annotations do not support importing custom YAML configurations.

If you are not familiar with YAML configuration, you can refer to the Introduction to YAML Configuration in Spring Boot

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

Cross-domain can be solved in the front end through JSONP, but JSONP can only send GET requests, not other types of requests. In RESTful applications, JSONP is very weak, so we recommend the backend through (CORS, Cross-origin Resource Sharing) to solve cross-domain problems. This solution is not unique to Spring Boot. In traditional SSM frameworks, cross-domain problems can be solved through CORS, but instead of configuring CORS in XML files, cross-domain problems can now be solved through @Crossorigin annotations. Spring Boot uses CORS to solve cross-domain problems

  • 7. Compare the pros and cons of Spring Security and Shiro?

Using Spring Security in Spring Boot is much easier, thanks to a number of very convenient out-of-the-box Starter options, including the Spring Security Starter. Even a single dependency can be added to protect all interfaces, so Spring Security is the preferred option for Spring Boot projects. Of course, this is just a combination of suggestions, purely technically speaking, no matter how the combination, there is no problem. Shiro has the following features compared to Spring Security:

  1. Spring Security is a heavyweight Security management framework; Shiro is a lightweight security management framework
  2. Spring Security is complex in concept and configuration. Shiro is simple in concept and configuration
  3. Spring Security is powerful; Shiro is simple
  • 8. How to realize session sharing in microservices?

In microservices, a complete project is divided into multiple different independent services, which are deployed independently on different servers, and their sessions are separated from the physical space. But often, we need to share sessions between different microservices. The common solution is Spring Session + Redis to achieve Session sharing. All microservices’ sessions are uniformly stored in Redis. When each microservice has related read and write operations on the session, it will operate the session on Redis. In this way, session sharing is realized. Spring Session is implemented based on the proxy filter in Spring, making session synchronization transparent and easy for developers. Spring Boot a dependency on session sharing, there is no simpler solution!

  • 9. How does Spring Boot implement hot deployment?

It’s easy to implement hot deployment in Spring Boot by introducing a DevTools dependency so that Spring Boot restarts automatically when a compiled file changes. In Eclipse, when the user presses the save button, Spring Boot will be automatically compiled and then restarted. As IDEA is automatically saved and not compiled during automatic saving, the developer needs to press Ctrl+F9 for compilation. After compilation, the project will be automatically restarted.

If only the page template has changed and the Java classes have not, you can easily implement hot deployment using the LiveReload plug-in without rebooting Spring Boot.

  • 10. How to implement scheduled tasks in Spring Boot?

Scheduled tasks are also a common requirement. Spring Boot supports scheduled tasks mainly from the Spring framework.

There are two main ways to use Scheduled tasks in Spring Boot: using the @Scheduled annotation in Spring and using a third-party framework called Quartz.

The way to use @Scheduled in Spring is primarily through the @Scheduled annotation.

If Quartz is used, Job and Trigger are defined as Quartz.

For details about scheduled tasks, see: Two ways to implement scheduled tasks in Spring Boot.

  • 11. How to maintain interface documents when the front and back ends are separated?

In most cases, we do front-end and back-end separated development through Spring Boot. There must be interface documentation for front-end and back-end separated development, otherwise the front-end and back-end would be deeply involved in the wraparound. A clumsy method is to use Word or MD to maintain the interface document, but it is inefficient. When the interface changes, everyone has to change the document. In Spring Boot, Swagger is a common solution to this problem. With Swagger, we can quickly generate an interface document website. Once the interface changes, the document will be automatically updated. SpringBoot provides Swagger2 and no need to maintain Swagger interface files.

  • 12. What is Spring Data?

Spring Data is a subproject of Spring. Used to simplify database access and support NoSQL and relational data storage. Its main goal is to make database access easy and quick. Spring Data has the following characteristics:

  1. The SpringData project supports NoSQL storage:
  2. MongoDB (document database)
  3. Neo4j (Graph database)
  4. Redis (Key/Value store)
  5. Hbase (Column Family Database)

Relational data storage technologies supported by the SpringData project:

  1. JDBC
  2. JPA

Spring Data Jpa aims to reduce the amount of Data access layer (DAO) development. The only thing you need to do is declare the interface to the persistence layer, and let Spring Data JPA do the rest for you! Spring Data JPA determines what logic the method needs to implement based on the name of the specification method.

  • 13. Can Spring Boot be configured using XML?

Spring Boot recommends Java configuration over XML configuration, but XML configuration is also available in Spring Boot, and an XML configuration can be introduced via the @importResource annotation.

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

The jar that Spring Boot projects eventually package into is an executable JAR that can be run directly through the java-jar xxx.jar command. This jar cannot be relied on by other projects as a normal JAR, and even if it does, it cannot use its classes.

The Spring Boot JAR cannot be relied upon by other projects, mainly because it is structurally different from regular JARS. A regular jar package, unzipped, contains our code. A Spring Boot executable jar package, unzipped, contains our code in the \ boot-INF \classes directory, and therefore cannot be referenced directly. If you must, you can add configuration to the pom.xml file to package the Spring Boot project into two Jars, one executable and one referenceable.

  • 15. What is the difference between bootstrap.properties and application.properties?

The bootstrap.properties configuration file may not be easy to encounter in pure Spring Boot development, but it is often encountered in conjunction with Spring Cloud, especially when some remote configuration files need to be loaded.

Bootstrap.properties is loaded before application.properties, and the configuration takes effect during the boot phase of the application context. It is typically used in Spring Cloud Config or Nacos. Bootstrap. properties is loaded by the Spring ApplicationContext’s parent class, which starts before the ApplicatonContext loads Application.properties.

Of course, the properties in the previous description can also be changed to YAML.

Spring Boot Interview question: Spring Boot interview question

Pay attention to the public account [Jiangnan little Rain], focus on Spring Boot+ micro service and front and back end separation and other full stack technology, regular video tutorial sharing, after attention to reply to Java, get Songko for you carefully prepared Java dry goods!