Springboot and Springcloud face questions

Source: Internet
Author: User
Tags solr

I. What is Springboot

1. Used to simplify the initial construction of the spring application and the development process using a specific way to configure (properties or yml files)
2. Create a separate spring reference program the Main method runs
3. Embedded Tomcat does not need to deploy the war file
4. Simplify MAVEN configuration
5. Automatic configuration spring add corresponding function starter Automation configuration

Two. What are the starter commonly used in springboot?

Can go to the Maven warehouse search for the following plug-ins, pom file dependencies can
Maven Warehouse official website: http://mvnrepository.com/
1.spring-boot-starter-web (embedded Tomcat and web development requires servlet and JSP support)
2.SPRING-BOOT-STARTER-DATA-JPA (Database support)
3.spring-boot-starter-data-redis (Redis database support)
4.SPRING-BOOT-STARTER-DATA-SOLR (SOLR Search application framework Support)
5.mybatis-spring-boot-starter (third-party mybatis Integration Starter)

Three. Principle of Springboot automatic configuration

[Email protected]

This comment tells Springboot "guess" how you would like to configure spring, based on the jar dependencies you have added.

If Spring-boot-starter-web has added Tomcat and spring MVC, this annotation automatically assumes that you are developing a Web application and adding the appropriate spring settings. will automatically go to Maven to read the Spring.factories file in each starter the file is configured with all the beans that need to be created in the spring container

2. Using @springbootapplication annotations

You can solve the problem of too many annotations on the head of the root class or configuration class (my own, that is, the main class), a @springbootapplication equivalent to @configuration, @EnableAutoConfiguration and @ Componentscan and have their default property values

Four. Springboot how to read a configuration file
    springboot默认读取配置文件为application.properties或者是application.yml
Application.properties.PNG

Springboot Integration of MyBatis process
Add MyBatis starter Maven Dependency
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
Adding @mapper annotations to the MyBatis interface
Configuring data source information in APPLICATION.YML

Five. Springboot How to add the "Modify code" automatic restart function
    添加开发者工具集=====spring-boot-devtools
Six. Micro-service
    以前的模式是所有的代码在同一个工程中 部署在同一个服务器中 同一个项目的不同模块不同功能互相抢占资源    微服务 将工程根据不同的业务规则拆分成微服务 微服务部署在不同的机器上 服务之间进行相互调用    Java微服务的框架有 dubbo(只能用来做微服务),spring cloud(提供了服务的发现,断路器等)
Seven. Springcloud how to achieve registration and discovery of services
    服务在发布时 指定对应的服务名(服务名包括了IP地址和端口) 将服务注册到注册中心(eureka或者zookeeper)    这一过程是springcloud自动实现 只需要在main方法添加@EnableDisscoveryClient  同一个服务修改端口就可以启动多个实例    调用方法:传递服务名称通过注册中心获取所有的可用实例 通过负载均衡策略调用(ribbon和feign)对应的服务
Eight. Ribbon and Feign differences

The ribbon adds Maven dependent Spring-starter-ribbon using @ribbonclient (value= "service name") to invoke the remote service corresponding method using Resttemplate
Feign add maven dependent Spring-starter-feign service provider provides external interface to callers using @FeignClient on interface ("Specify Service name")
The difference between ribbon and feign:
Both the ribbon and the feign are used to invoke other services, but in different ways.
1. The annotations used by the start-up class are different, and the Ribbon is @ribbonclient,feign with @enablefeignclients.
2. Depending on the location of the service, the Ribbon is declared on the @ribbonclient annotation and feign is used in the interface that defines the abstract method @feignclient declaration.
3. In different ways, the ribbon needs to build its own HTTP request, simulate an HTTP request and then send it to other services using resttemplate, which is cumbersome.
Feign has been improved on the basis of the ribbon, using interfaces to define methods of other services that need to be invoked as abstract methods.
You do not need to build your own HTTP requests. Note, however, that the annotations of the abstract method, the method signature, and the method of providing the service are exactly the same.

Nine. The role of the Springcloud circuit breaker

The caller waits for a call when a service invokes another service because of a network cause or a problem with its own cause
More service requests to these resources when the
Cause more requests to wait so there will be cascading effect (avalanche effect) breaker is to solve this problem breaker
Has a fully open state
A certain number of times within a given time can not be called and repeatedly detect no signs of recovery The breaker is completely open, that
The next request will not be requested to the service half open, a short period of recovery signs the circuit breaker will send some of the request to the service when
When the circuit breaker shuts down when the service is in normal condition, it can call the circuit breaker off normally.



Springboot and Springcloud face questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.