spring cloud篇 eureka client(服务提供者)

项目结构
这里写图片描述

一:服务管理(dcb-lott-service)pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dcb-lott-app</artifactId>
        <groupId>com.dcb</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modules>
        <module>dcb-lott-activety</module>
        <module>dcb-lott-sso</module>
    </modules>
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <artifactId>dcb-lott-service</artifactId>

    <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>

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

        <!-- 自己封装的工具包,需手动去除 -->
        <dependency>
            <groupId>com.dcb</groupId>
            <artifactId>common-utils</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.9</version>
        </dependency>
    </dependencies>
</project>

二:服务提供者(单个的服务既可以为服务提供者,也可为服务消费者)pom文件

<dependencies>
        <!-- 服务提供者所需依赖,由于所有单个服务交由dcb-lott-service管理,故将其作为公共依赖加入父级
            此处无需再加入依赖,如若不需要父级管理则必须引入此依赖包
        <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>

在spring boot启动类加上@EnableEurekaClient注解

/**
 * @Auther: yxc
 * @Date: 2018/8/1 10:47
 * @Description:
 */
@EnableEurekaClient
@SpringBootApplication
public class Application {

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

服务提供者application.yml

eureka:
  client:
  #服务提供者需指定注册中中心地址d
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/
server:
  port: 8081
spring:
  application:
    name: dcb-lott-sso

注意:
2.服务提供者spring.application.name尤为重要,之后的服务消费者都需要通过此配置寻找服务

接下来启动服务提供者,必须先启动注册中心,在注册中心界面即可查看服务提供者信息
这里写图片描述

可再启动一个服务,将端口改为8082,用于负载均衡的调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值