The latest collection of JAVA interview questions (9)

Spring Boot / Spring Cloud

104. What is spring boot?

In the big family of Spring framework, many derivative frameworks have been produced, such as Spring, SpringMvc framework, etc. The core content of Spring is inversion of control (IOC) and dependency injection (DI). The so-called inversion of control is not a technology, but It is a kind of thought. In terms of operation, it is created in the spring configuration file. Dependency injection means that the spring container provides resources for an object of the application, such as reference objects, constant data, and so on.

SpringBoot is a framework, a brand new programming specification, which simplifies the use of the framework. The so-called simplification refers to the simplification of a large number of and cumbersome configuration files required in many frameworks of Spring, so SpringBoot is a framework serving the framework , The scope of service is to simplify configuration files.

105. Why use spring boot?

  • Spring Boot makes coding easy
  • Spring Boot makes configuration simple
  • Spring Boot makes deployment easy
  • Spring Boot makes monitoring easy
  • Shortcomings of Spring

106. What is the spring boot core configuration file?

Spring Boot provides two commonly used configuration files:

  • properties file
  • yml file

107. What types of spring boot configuration files are there? What is the difference between them?

Spring Boot provides two commonly used configuration files, namely the properties file and the yml file. Compared with the properties file, the yml file is younger and has many pitfalls. It can be said that Cheng Ye Xiao He defeat Xiao He, yml uses spaces to determine the hierarchical relationship, so that the configuration file structure is clear, but it will also destroy the hierarchical relationship due to trivial spaces.

108. What are the ways to achieve hot deployment of spring boot?

There are two ways to implement SpringBoot hot deployment:

①. Use spring loaded
to add the following code to the project:

<build>
        <plugins>
            <plugin>
                <!-- springBoot编译插件-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <!-- spring热部署 -->
                    <!-- 该依赖在此处下载不下来,可以放置在build标签外部下载完成后再粘贴进plugin中 -->
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.6.RELEASE</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

After adding, you need to use the mvn command to run:

First find the Edit configurations in IDEA, and then perform the following operations: (click on the "+" in the upper left corner, then select maven, the right panel will appear, enter the command as shown in the red line, and you can name the command ( Named here as MvnSpringBootRun))

Insert picture description here
Click save and it will appear in the running part of IDEA project, just click the green arrow to run

Insert picture description here

②. Use spring-boot-devtools

Add dependencies in the project's pom file:

<!--热部署jar-->
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-devtools</artifactId>
 </dependency>

Then: use shift+ctrl+alt+"/" (shortcut key in IDEA) to select "Registry" and then check compiler.automake.allow.when.app.running

109. What is the difference between jpa and hibernate?

  • JPA Java Persistence API is the standard ORM interface of Java EE 5 and part of the ejb3 specification.

  • Hibernate, a very popular ORM framework today, is an implementation of JPA, but its function is a superset of JPA.

  • The relationship between JPA and Hibernate can be simply understood as JPA is the standard interface and Hibernate is the implementation. So how does Hibernate realize this relationship with JPA. Hibernate is mainly implemented through three components, hibernate-annotation, hibernate-entitymanager and hibernate-core.

  • Hibernate-annotation is the basis of Hibernate's support for annotation configuration. It includes standard JPA
    annotation and Hibernate's own special function annotation.

  • hibernate-core is the core implementation of Hibernate, which provides all the core functions of Hibernate.

  • hibernate-entitymanager implements standard JPA, which can be regarded as an adapter between hibernate-core and JPA. It does not directly provide ORM functions, but encapsulates hibernate-core, making Hibernate conform to JPA specifications.

110. What is spring cloud?

Literally, Spring Cloud is a framework dedicated to distributed systems and cloud services.

Spring Cloud is a new member of the entire Spring family and an inevitable product of the recent hot cloud services.

Spring Cloud provides developers with tools to quickly build some common patterns in distributed systems, such as:

  • Configuration management
  • Service registration and discovery
  • breaker
  • Intelligent routing
  • Inter-service call
  • Load balancing
  • Micro-agent
  • Control bus
  • One-time token
  • Global lock
  • Leader election
  • Distributed session
  • Cluster status
  • Distributed messaging
  • ……

Using Spring Cloud, developers can implement services and applications of these patterns out of the box. These services can run in any environment, including distributed environments, as well as developers’ own laptops and various hosting platforms.

111. What is the function of the spring cloud circuit breaker?

Hystrix is ​​used in Spring Cloud to implement the circuit breaker function. The circuit breaker can prevent an application from trying to perform an operation multiple times, that is, it is likely to fail, allowing it to continue without waiting for failure recovery or wasting CPU cycles, and it determines the The failure is permanent. The circuit breaker mode also enables the application to detect whether the fault has been resolved, and if the problem appears to have been corrected, the application can try to call the operation.

The circuit breaker increases the stability and flexibility to provide a system with stability, while the system recovers from a fault, and minimizes the impact of this fault on performance. It can help quickly reject an operation that is likely to fail, instead of waiting for the operation to time out (or not return) request, in order to maintain the system's response time. If the circuit breaker increases the time of each change of state event, this information can be used to monitor the health of the components of the system protected by the circuit breaker, or to alert the administrator when the circuit breaker is tripped to be in the open state.

112. What are the core components of spring cloud?

①. Service discovery-Netflix Eureka

A RESTful service used to locate middle-tier services running in the AWS region (Region). It consists of two components: Eureka server and Eureka client. The Eureka server is used as a service registration server. Eureka client is a java client used to simplify the interaction with the server, as a polling load balancer, and provide failover support for services. Netflix uses another client in its production environment, which provides weighted load balancing based on traffic, resource utilization, and error status.

②. Load balancing on the customer service side-Netflix Ribbon

Ribbon, mainly provides client-side software load balancing algorithms. The Ribbon client component provides a series of complete configuration options, such as connection timeout, retry, retry algorithm, etc. Ribbon has built-in pluggable and customizable load balancing components.

③. Circuit breaker-Netflix Hystrix

The circuit breaker can prevent an application from trying to perform an operation multiple times, that is, it is likely to fail, allowing it to continue without waiting for failure recovery or wasting CPU cycles, and it determines that the failure is permanent. The circuit breaker mode also enables the application to detect whether the fault has been resolved. If the problem seems to have been corrected, the application can try to call the operation.

④. Service gateway——Netflix Zuul

Similar to nginx, the reverse proxy function, but netflix has added some features to cooperate with other components.

⑤. Distributed configuration-Spring Cloud Config

This is still static and needs to be used with Spring Cloud Bus to implement dynamic configuration updates.

Guess you like

Origin blog.csdn.net/weixin_42120561/article/details/114934246