Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Spring Boot?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you to what Spring Boot is, the content is very detailed, interested friends can refer to it, I hope it can help you.

How is Spring Boot autoconfiguration implemented?

The Spring Boot project startup annotation is @SpringBootApplication, which actually consists of the following three annotations:

@Configuration

@ComponentScan

@EnableAutoConfiguration

@EnableAutoConfiguration is the entry for automatic configuration. This annotation imports AutoConfigurationImportSelector through @Import annotation, and loads the configuration information of META-INF/spring.factory. Then filter out the data with EnableAutoConfiguration as key, load it into IOC container, and realize automatic configuration function!

2 What is an embedded server? Why do we use embedded servers?

Think about what it takes to deploy an application on your virtual machine.

Step 1: Install Java

Part 2: Install Web or application servers (Tomat/Wbescope/Weblogic, etc.)

Part Three: Deploying the Application War Package

If we want to simplify these steps, how should we do it?

Let's think about how to make servers part of an application.

All you need is a virtual machine with Java installed, and you can deploy applications directly on it.

Isn't that great?

This idea is the origin of embedded servers.

When we create a deployable application, we embed the server (tomcat, for example) within the deployable server.

For example, for a Spring Boot application, you can generate an application jar that contains Embedded Tomcat. You can run web applications just like normal Java applications.

An embedded server is our executable unit containing the binary file of the server (for example, tomcat.jar).

Microservices call multiple interfaces at the same time, how to support transactions?

Distributed transaction support can be solved using Spring Boot integration Aatomikos, but I generally do not recommend using this because using distributed transactions will increase the response time of requests and affect the TPS of the system. In practice, message compensation mechanisms are used to handle distributed transactions.

What is the relationship between shiro and oauth and cas? Ask how your company's permissions are designed, and what the difference is between these concepts.

CAS and oauth are components that solve single sign-on, while shiro is mainly responsible for permission security, so the function points are inconsistent. However, it often requires a single login and permission control to be used together, so there are combinations such as cas+shiro or oauth+shiro.

Token is generally generated by the server after the client logs in. Each time the server is accessed, it will be verified. Generally, it can be saved to memory, or it can be placed on other media. Redis can be used as Session sharing. If there are several loads on the front-end web server, but it needs to keep the user logged in. This scenario is more common.

Our company uses oauth+shiro to manage background permissions. oauth is responsible for unified login authentication in multiple backgrounds, and shiro is responsible for granting different access rights to login users.

5. Communication between services, how to choose between Restful and Rpc?

In traditional SOA governance, rpc is mostly used;Spring Cloud uses restful by default for communication between services. Rpc will be a bit more efficient than restful, but for most companies this will have little impact. I recommend restful as an easy way to communicate between services implemented in different languages.

6. How to design stateless services?

For stateless services, first of all, state: If a piece of data needs to be shared by multiple services in order to complete a transaction, that piece of data is called state. Services that depend on this "state" data are called stateful services, whereas stateless services are called stateless services.

Then this stateless service principle does not mean that state is not allowed in the microservice architecture. The real meaning of the expression is to change the stateful business service to a stateless computing service, so the state data will be migrated to the corresponding "stateful data service" accordingly.

Scenario Description: For example, the data cache and Session cache we previously established in local memory should be migrated to distributed cache storage in the current microservice architecture, so that the business service becomes a stateless compute node. After migration, on-demand dynamic scaling can be achieved, and microservice applications dynamically add and delete nodes at runtime, so there is no need to consider how cache data is synchronized.

7. Spring Cache Three commonly used cache annotations and meanings?

@Cacheable, used to declare that the method is cacheable, store the result in the cache so that subsequent calls with the same parameters do not need to execute the actual method, directly from the cache value.

@CachePut, a method annotated with @CachePut does not check the cache for previously executed results before execution, but executes the method each time and stores the execution results in the specified cache as key-value pairs.

@CacheEvict, is used to mark the method or class that needs to clear the cache element. When marked on a class, it means that the execution of all methods in it will trigger the cache clearing operation.

How does Spring Boot support cross-domain requests?

For security reasons, modern browsers must comply with the same-origin policy when requesting HTTP, otherwise it is a cross-domain HTTP request, which is prohibited by default. Different IP (domain name), or different ports and protocols (such as HTTP and HTTPS) will cause cross-domain problems.

Common front-end solutions include:

① JSONP is used to support cross-domain requests. The principle of JSONP to implement cross-domain requests is simply to dynamically create labels, and then use SRC to obtain data across domains without being constrained by the same-origin policy. The disadvantage is that the backend needs to cooperate with the output of specific return information.

② Use the mechanism of reaction proxy to solve the cross-domain problem. When the front-end requests, the request is sent to the backend of the same origin address first, and the cross-domain access is avoided by forwarding the backend request.

HTML5 supports the CORS protocol. CORS is a W3C standard, full name is "cross-origin resource sharing"(Cross-origin resource sharing), allowing browsers to cross-origin servers, XMLHttpRequest request request, thus overcoming the limitation that AJAX can only be used from the same source. It adds a special Header[Access-Control-Allow-Origin] to the server to tell the client about cross-domain restrictions. If the browser supports CORS and determines that Origin passes, XMLHttpRequest will be allowed to initiate cross-domain requests.

The frontend uses CORS protocol, which requires backend settings to support non-homologous requests. Spring Boot settings support non-homologous requests in two ways.

First, configure CorsFilter.

@Configurationpublic class GlobalCorsConfig { @Bean public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.addAllowedOrigin("*"); config.setAllowCredentials(true); config.addAllowedMethod("*"); config.addAllowedHeader("*"); config.addExposedHeader("*"); UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); configSource.registerCorsConfiguration("/** ", config); return new CorsFilter(configSource); }}

You need to configure the above code. The second way is a bit simpler.

Second, add to the startup class:

public class Application extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/** ") .allowCredentials(true) .allowedHeaders("*") .allowedOrigins("*") .allowedMethods("*"); What is the difference between JPA and Hibernate? Can JPA support dynamic SQL?

JPA itself is a specification, its essence is an ORM specification (not an ORM framework, because JPA does not provide an ORM implementation, only a specification) because JPA is a specification, so it only provides some related interfaces, but the interfaces cannot be used directly. JPA requires some JPA implementation at the bottom, Hibernate is an implementation set of JPA.

JPA is to create corresponding tables and fields according to the annotations of entity classes. If you need to dynamically create tables or fields, you need to dynamically construct corresponding entity classes, and then call JPA to refresh the entire Entity. Dynamic SQL, mybatis support the best, jpa can also support, but not as flexible as Mybatis.

What is Spring, Spring Boot and Spring Cloud?

Spring Ioc and Spring Aop, the two core functions of Spring at the beginning, made Spring, Spring in these two core functions on the continuous development, only to have a series of great products such as Spring transactions, Spring Mvc, etc., and finally made the Spring Empire, to the late Spring can solve almost all problems in enterprise development.

Spring Boot was developed on top of the strong Spring Empire ecosystem, and was invented not to replace Spring , but to make it easier for people to use Spring.

Spring Cloud is an ordered collection of frameworks. It makes use of the development convenience of Spring Boot to skillfully simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, message bus, Load Balancer, circuit breaker, data monitoring, etc., all of which can be started and deployed with one click in the development style of Spring Boot.

Spring Cloud is a development framework that provides a series of functions to solve service governance in microservices architecture, and Spring Cloud is completely based on Spring Boot. Spring Cloud integrates excellent components in the open source industry by using Spring Boot features, and provides a set of solutions for service governance in microservices architecture.

Express the relationship between them by a set of implausible inclusion relationships.

Spring ioc/aop > Spring > Spring Boot > Spring Cloud

About what is Spring Boot to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report