A preliminary study of Spring (1) boot, swagger, eureka, hystrix

1. Create a Spring Boot simple response request service 1. Add       <dependency>           <groupId>org.springframework.boot</groupId>           <artifactId>spring-boot-starter-web</artifactId>       </dependency
   to pom.xml in the project >    2. Create a boot startup program, the keyword @SpringBootApplication, which implements the main method as the process entry SpringApplication.run(DemoApplication.class, args);    3. Creates a controller, the keyword @RestController, is registered as controller, @RequestMapping( value="/demo") is the path mapping. 2. Integrate swagger    1. Add in the project pom.xml:     <!--swagger integration-->     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-swagger2</artifactId>         <version>2.7 .0<















    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.7.0</version>
    </dependency>  
   2.添加配置类
            @Component
            @Configuration
            @EnableSwagger2
            public class Swagger2Config{
                    @Bean
                    public Docket createRestApi() {
                        return new Docket(DocumentationType.SWAGGER_2)
                                .select()
                                .apis(RequestHandlerSelectors.any())
                                .paths(PathSelectors.any())
                                .build();
                    }
            }

3. Integrate the eureka project

        1. The server downloads eureka.war from the Internet and puts it under tomcat. After starting tomcat, it can be accessed through http:ip:port/eureka

        2. The client is in the project Add           

                    org.springframework.cloudspring-cloud-starter-eureka1.3.1.RELEASE to pom.xml

        3. Add @EnableEurekaClient in startup boot to start eureka customer registration

        4. The following content needs to be added to the property file #application

          name, if not item, the interface application displays unknown

          spring.application.name=demo

          eureka.client.serviceUrl.defaultZone=http://localhost:8080/eureka/v2/

          eureka.instance.status-page-url=http://localhost :${server.port}/swagger-ui.html

4. Integrate the Hystrix project

        1. Add          

            org.springframework.cloudspring-cloud-starter-hystrix1.3.1.RELEASE to the project pom.xml

        2. Add the @EnableHystrix annotation to the boot starter to start hystrix

        3. Add @HystrixCommand(fallbackMethod = "Method name") The method in the method name needs to be consistent with the original method parameters

5. Integrate Hystrix Dashboard

        1. Add

            org.springframework.bootspring-boot-starter-actuator org.springframework.cloudspring-cloud-starter- hystrix-dashboard

        2. Add @EnableHystrixDashboard to the boot startup class

        3. Start to view the EnableHystrixDashboard address: http://ip:port/hystrix, add http://ip:port/hystrix.steam at the stream, click monitor Check.


demo, git address: https://github.com/leaf-it/demo.git


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326373293&siteId=291194637