(Java Daily Talk: Day 17 - Employment Interview Knowledge Clearance Strategy) SpringBoot and SpringCloud

What is Spring Boot?

Spring Boot is a sub-project under the Spring open source organization. It is a one-stop solution for Spring components. It mainly simplifies the difficulty of using Spring, saves heavy configuration, and provides various starters so that developers can get started quickly.

What are the advantages of Spring Boot?

Spring Boot mainly has the following advantages:

1. Easy to use and improve development efficiency

2. Ready to use out of the box, away from cumbersome configuration

3. Provide a series of common non-business functions for large-scale projects

4. No code generation and no xml configuration required

5. Avoid a large number of Maven imports and various version conflicts

What is JavaConfig?

SpringJavaConfig is a product of the Spring community, which provides a pure Java method for configuring the Spring IoC container. So it helps to avoid using XML configuration. The advantages of using JavaConfig are:

1. Object-oriented configuration. Since the configuration is defined as a class in javaConfig, users can take full advantage of object-oriented features in Java. One configuration class can inherit another, override its bean methods, etc.

2. Reduce or eliminate XML configuration. The benefits of externalized configuration based on the principles of dependency injection have been proven.

3. Type safety and refactoring friendly

Compare the advantages and disadvantages of Spring Security and Shiro?

Since Spring Boot officially provides a large number of very convenient out-of-the-box Starters, including Spring Security Starter, it is easier to use Spring Security in Spring Boot, and even only need to add a dependency to protect all interfaces, so, If it is a Spring Boot project, generally choose Spring Security.

Compared with Spring Security, Shiro has the following main features:

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

        2. The concept of Spring Security is complex and the configuration is cumbersome; the concept of Shiro is simple and the configuration is simple

        3. Spring Security is powerful; Shiro is simple

What is the difference between the jar achieved by Spring Boot and the ordinary jar?

The jar packaged by the Spring Boot project is an executable jar. This kind of jar can be run directly through the java jar xxx.jar command. This kind of jar cannot be relied on by other projects as an ordinary jar. Even if it depends on it, the classes in it cannot be used .

Spring Boot's jar cannot be relied on by other projects, mainly because it has a different structure from ordinary jars. After the ordinary jar package is decompressed, it is the package name, and the package is our code. After the executable jar packaged by Spring Boot is decompressed, our code is in the \Boot-INF\classes directory, so it cannot be directly referenced. If you have to reference it, you can add configuration to the pom.xml file and package the Spring Boot project into two jars, one executable and one referenceable.

What are the ways to run Spring Boot?

1. Package with the command line or run in a container

2. Run with Maven/Gradle plugin

3. Directly execute the main method to run

Principles of Spring Boot

Spring Boot is a new framework provided by the Pivotal team, which is designed to simplify the initial construction and development process of new Spring applications. The framework uses a specific way to configure, so that developers no longer need to define templated configuration. In this way, Spring Boot aims to be a leader in the field of rapid development. Its characteristics are as follows:

1. Create an independent Spring application subroutine

2. Embedded Tomcat, no need to deploy WAR files

3. Simplify Maven configuration

4. Automatically configure Spring

5. Provides production-ready features such as metrics, health checks, and external configuration

6. Absolutely no code generation and no XML configuration required

What is Spring Cloud?

Spring Cloud is an ordered collection of a series of frameworks, which subtly simplifies the development of distributed system infrastructure by using the development convenience of Spring Boot, such as service discovery registration, configuration center, intelligent routing, message bus, load balancing, circuit breaker , data monitoring, etc., can use the Spring Boot development style to achieve one-click startup and deployment. Spring Cloud does not repeat the manufacture of wheels, it just combines the mature and practical service frameworks developed by various companies, and repackages through the Spring Boot style to shield the complex configuration and implementation principles. The author left a set of distributed system development tools that are easy to understand, easy to deploy and easy to maintain.

What are the advantages of using Spring Cloud?

When using Spring Boot to develop distributed microservices, we face the following problems

  1. Complexity associated with distributed systems - this overhead includes network issues, latency overhead, bandwidth issues, security issues
  2. Service Discovery - Service discovery tools manage how processes and services in a cluster find and talk to each other. It involves a service directory, registering services in that directory, and then being able to find and connect to services in that directory.
  3. Redundancy - Redundancy issues in distributed systems
  4. Load Balancing - Load balancing improves workloads across multiple computing resources
  5. Performance-Issues Performance issues due to various operational overheads

What does service registration and discovery mean? How does Spring Cloud implement it?

When we start a project, we usually do all the configuration in properties files. Adding and modifying these properties becomes more complex as more services are developed and deployed. Some services may be down and some locations may change. Changing properties manually can be problematic. Eureka Service Registration and Discovery can help in this situation. Since all services are registered on the Eureka server and the lookup is done by calling the Eureka server, there is no need to deal with any changes and processing of service locations.

What is the meaning of load balancing?

In computing, load balancing improves the distribution of workload across multiple computing resources such as computers, computer clusters, network links, central processing units, or disk drives. Load balancing aims to optimize resource usage, maximize throughput, minimize response times and avoid overloading any single resource. Using multiple components for load balancing rather than a single component may improve reliability and availability through redundancy.

Introduction to SpringCloud Fuse Mechanism

In the Spring Cloud framework, the fuse mechanism is implemented through Hystrix. Hystrix will monitor the status of calls between microservices, and when the failed calls reach a certain threshold, the fuse mechanism will be activated. The annotation of the fuse mechanism is @HystrixCommand, Hystrix will find the method with this annotation, and associate this method with the agent connected to the fuse. Currently, @HystrixCommand only works when the class is annotated with @Service or @Component.

Spring Cloud compared to Dubbo, in what scenario is Spring Cloud used?

The problem domains solved by the two are different: Dubbo is always positioned as an RPC framework, while Spring Cloud aims to be a one-stop solution under the microservice architecture.

Spring Cloud abandons Dubbo's RPC communication and adopts the REST method based on HTTP.

Strictly speaking, both approaches have their pros and cons. Although to a certain extent, the latter sacrifices the performance of service calls, it also avoids the problems caused by the native RPC mentioned above. Moreover, REST is more flexible than RPC. The service provider and caller rely only on a paper contract, and there is no strong dependency at the code level. This is more appropriate in a microservice environment that emphasizes rapid evolution.

 

Guess you like

Origin blog.csdn.net/weixin_50249953/article/details/124527870