First install the consul environment, referring to the previous article: http://blog.csdn.net/mn960mn/article/details/51753893
Project planning, 2 service-side, 1 clients
First look at the service side,
One: server 1:
Project Dependencies
Note that adding Spring-boot-actuator is for the project to have access to the/health path to determine whether the service is healthy
Package com.pp.consul1;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigur
# Ribbon timeout setting # ribbon: # ConnectTimeout: 500 # ReadTimeout: 3000
Hystrix is a configuration pitfall for a long time. The Spring Cloud I use is Dalston SR1, Which is newer than other materials on the Internet, because Feign's support for Hystrix is disabled by default in the new version, therefore, manually enable feign through configuration. hystrix. enabled = true, so that service downgrade and other functions will be effective.
Application Startup Program
@
: eureka-server
Create a springboot project: eureka-server. Its pom. xml configuration is as follows:
To implement a service registration center, you only need to use the @ EnableEurekaServer Annotation on the project startup class EurekaServerApplication.
@EnableEurekaServer @SpringBootApplication public class EurekaServerApplication{ public static void main(String[] args) { new SpringApplicationBuilder(EurekaServerApplication.class) .web
certain load balancing policy through Ribbon.
(4) If the Feign, service client, and services need to access each other, you can use RestTemplate or Feign client. By default, it uses Ribbon for load balancing.
(5) Hystrix, monitoring and circuit breaker. We only need to add the Hystrix tag to the service interface to implement monitoring and circuit breaker functions for this interface.
(6) Hystrix Dashboard, monitoring panel, which provides an interface to monitor the time consumed by service c
Chapter 4 springboot + swagger and springbootswagger
NOTE: Refer
Http://www.jianshu.com/p/0465a2b837d2
Swagger is used to define API documentation.
Benefits:
Frontend and backend separation Development
API documentation is very clear
You do not need to enter the browser URL to access the Controller during the test.
The traditional method of testing input URLs is inconvenient for passing parameters in post requests (of course, browser plug-ins such as postman can be used)
Simple Integratio
-serverserver.port=7001# Configure Service Registry Eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/# Git repository configuration Spring.cloud.config.server.git.uri=xxspring.cloud.config.server.git.searchPaths= Xxspring.cloud.config.server.git.username=Usernamespring.cloud.config.server.git.password= PasswordIn the application main class, new annotations are added to @EnableDiscoveryClient register the Config-server with the service registry configured above.@EnableDiscoveryC
;org.springframework.cloudgroupid> artifactId> Spring-cloud-config-monitorartifactid> dependency> Application.properties to configure the warehouse description and Message Queuing address, if it is a private project, you also need to configure the user name passwordspring.cloud.config.server.git.uri=https://github.com/seagrape/SpringCloudConfig.gitspring.cloud.config.server.git.searchPaths=alan-config-repo#spring.cloud.config.server.git.username=sihan2#spring.cloud.config.server.git.passw
I. OverviewOne of the most popular features in Springboot is the automatic configuration. Springboot helps us to configure the entire development environment based on automatic configuration, which allows us to not have to do the repetitive configuration work every time.In this, we will analyze the principle of automatic configuration.Two. program start-Up class@SpringBootApplication Public class Springbootrunnerclass { publicstaticvoid main
and add a file named src/main/java/Example. java:
import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@RestController@EnableAutoConfigurationpublic class Example { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(Example.class, args); }}
Use the "default" Pa
lot of errors.@EnableAutoConfiguration @componentscan@springbootapplication Public class Application { publicstaticvoid main (string[] args) { Springapplication.run (Application. class , args);} }Integrate MyBatis to Springboot1. Add dependencies springboot dependencies for MyBatis -Dependency> groupId>Org.mybatis.spring.bootgroupId> Artifactid>Mybatis-spring-boot-starterArtifactid> version>1.0.0version>Depe
implementation of the interface.Define an interface
123
publicinterfacePerson {String sayHello(String name);}
Implementation class
123456789101112131415
@Componentpublic class Chinese implements Person {@Timer@Overridepublic String sayHello(String name) {System.out.println("-- sayHello() --");return name + " hello, AOP";}public void eat(String food) {System.out.println("我正在吃:" + food);} }
The @Timer annotations Here are a general note tha
org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @mapperscan (" Com.zns.domain ") public class Restfulapplication {public static void main (string[] args) {Springapplication.run(Restfulapplication.class, args); }}It turns out this is the place to be. The official documentation explains that @SpringBootApplication annotations are equivalent to using @configuration, @Enabl
A pure SmileSource: http://www.ityouknow.com/Copyright belongs to the author, please specify the source of the reprintHystrix-dashboard is a real-time monitoring tool for Hystrix, through Hystrix dashboard we can visually see the request response time of each hystrix command, request the success rate and other data. But using only Hystrix dashboard, you can only see the service information in a single app, which is obviously not enough. We need a tool that allows us to summarize data from multip
1. Set up gitHttps://git.oschina.net/rigid/hr.gitUpload the following file:Hr_config/my-client.ymlHr_config/my-client-uat.yml2. Add Config server PackageCom.example.demo;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.cloud.config.server.EnableConfigServer, @SpringBootApplication @enableconfigserver Public classspringcloudserverapplication { Public Static voi
From the previous section: Springboot 02_ returns JSON data and can return JSON data, since some people are accustomed to different JSON frameworks, such as Fastjson, Here's how to integrate Fastjson in Springboot to enable JSON serialization of data.There are two ways to integrate when using Fastjson, but you need to introduce a Fastjson dependency package1: Introduction of Fastjson Dependency PackagesDependency> groupId>Com.alibabagroupId> Artifactid>FastjsonArtifactid> version>1.2.31
ObjectiveIn the first few chapters we have seen the springboot for us to do automatic configuration, indeed convenient and fast, but for beginners, if not understand springboot internal starting principle, will inevitably suffer. So this time the blogger will be with you step by step to uncover the mystery of springboot, let it not mysterious.BodyIf we develop any spring boot project, we will use the following startup classAs you can see from the code above, Annotation definitions (@
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.