zoukankan      html  css  js  c++  java
  • spring cloud 服务提供者

    1. pom 依赖:


    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    </parent>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>


    </dependencies>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Camden.SR7</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>

    </dependencies>
    </dependencyManagement>
    </project>

    2. 启动类:

    @SpringBootApplication
    @EnableEurekaClient
    public class HelloApplication {

    public static void main(String[] args) {
    SpringApplication.run(HelloApplication.class, args);
    }
    }

    3. 业务逻辑

    @RestController
    public class HelloController {
    private static Logger LOG = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private DiscoveryClient client;

    @RequestMapping("/hello")
    public String hello() throws InterruptedException {
    int time = new Random().nextInt(2000);
    LOG.info("时长是:{}",time);
    Thread.sleep(time);
    ServiceInstance instance = client.getLocalServiceInstance();
    String msg = "host:" + instance.getHost() + ",端口:" + instance.getPort() + ",serviceId:" + instance.getServiceId();
    LOG.info(msg);
    return msg;
    }
    }

    4. 配置:

    server:
    port: 8086
    spring:
    application:
    name: hello-service
    eureka:
    client:
    serviceUrl:
    defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server2:8762/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
    instance:
    preferIpAddress: true

  • 相关阅读:
    kylin_学习_00_资源帖
    Saiku_学习_03_Saiku+Kylin构建多维分析OLAP平台
    Saiku_学习_02_Schema Workbench 开发mdx和模式文件
    Tomcat_总结_02_单机多实例
    Saiku_学习_01_saiku安装与运行
    【HDU】1693 Eat the Trees
    【Ural】1519. Formula 1
    蒟蒻修养之tc蓝名计划
    【UVa】11270 Tiling Dominoes
    【POJ】2406 Power Strings
  • 原文地址:https://www.cnblogs.com/maohuidong/p/9881087.html
Copyright © 2011-2022 走看看