[Tencent Alibyte Java must ask] This is the correct way to open the interview preparation! Collect it now!

2020 latest Java collection of common interview questions + detailed answers (9)

Continue to update Java related materials. Recently, I have spent 7 days consulting the latest interview news of the big guys in an effort to collect more comprehensive interview information. If you want to see the first few collections, you can go to my homepage to find them.

Some of the answers are summarized by myself, and some are collected on the Internet. Don't panic after watching these interviews! If you have more experience, you can share it in the comments. If you have any mistakes, you are welcome to point it out. Please let me know, thank you~

十一、Spring Boot / Spring Cloud

83. 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 an idea. In terms of operation, it refers to the creation of <bean> 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, etc.

   

SpringBoot is a framework, a brand-new programming specification. Its production 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 that serves the framework , The scope of service is to simplify configuration files.

 

84. Why use spring boot?

 

  • Spring Boot makes coding easy

  • Spring Boot makes configuration simple

  • Spring Boot makes deployment easy

  • Spring Boot makes monitoring simple

  • Shortcomings of Spring

 

85. What is the spring boot core configuration file?

 

Spring Boot provides two commonly used configuration files:

 

  • properties file

  • yml file

 

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

 

Spring Boot provides two commonly used configuration files, which are properties files and yml files. 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.

Although I have provided you with questions and answer analysis, it is best for you to check the questions for yourself, and then you will learn more.           

87. What ways can spring boot achieve hot deployment?

 

There are two ways to implement SpringBoot hot deployment:

 

①. 使用spring loaded

 

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 do the following: (click 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 MvnSpringBootRun))

    

    

 

Click save and it will appear in the running part of IDEA project, click the green arrow to run

 

 

②. 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 check compiler.automake.allow.when.app.running

 

88. 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 so that Hibernate conforms to JPA specifications.

 

89. 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 recent 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

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

 

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

 

Hystrix is ​​used in Spring Cloud to implement the function of a circuit breaker. 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 the 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.

 

91. 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 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, and retry algorithm. 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 the failure to recover 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, 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 cooperate with Spring Cloud Bus to achieve dynamic configuration updates.

At last

The content of the interview questions is over here, there will be more updates in the follow-up, I hope it will be helpful to everyone.

Finally, I want to say something to you. I have worked for so many years and have interviewed some people for others. Whether it is from the perspective of the interviewer or the leader, in addition to interview skills and experience, great technology and project experience are also their trump cards and confidence. Core technology sharing of first-tier manufacturers

 It took me a long time to sort out some learning materials. What I posted above is the tip of the iceberg in the materials. I hope I can help you! Click to learn the secret code together: csdn

                         

  I will share more pure dry goods articles in the follow-up, and hope to really help you. Your support is my biggest motivation! Welcome to follow and like

                                                       

Guess you like

Origin blog.csdn.net/weixin_50333534/article/details/108954679