eureka注册接口php,SpringCloud使用eureka注册服务(提供接口)

1、新建maven项目

2、引入jar依赖

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.example

service-member

0.0.1-SNAPSHOT

jar

service-member

Demo project for Spring Boot

org.springframework.boot

spring-boot-starter-parent

2.0.3.RELEASE

UTF-8

UTF-8

1.8

Finchley.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-eureka

org.springframework.boot

spring-boot-starter-test

test

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

org.springframework.boot

spring-boot-maven-plugin

3、新建application.yml文件

eureka:

client:

service-url:

defaultZone: http://localhost:8888/eureka/

server:

port: 8762

spring:

application:

name: service-member

4、新建controller

package com.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

import java.util.List;

@RestController

public class MemberController {

@RequestMapping("/getMemberAll")

public List getMemberAll() {

List listUser = new ArrayList();

listUser.add("zhangsan");

listUser.add("lisi");

listUser.add("wangwu");

return listUser;

}

}

5、修改启动类,添加注解

package com.example.servicemember;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication

@EnableEurekaClient

@ComponentScan("com.example.controller")

public class ServiceMemberApplication {

public static void main(String[] args) {

SpringApplication.run(ServiceMemberApplication.class, args);

}

}

6、启动,观察注册中心

7ef7bb6790422652d0aa63dc66d779f7.png

64e12ff5dc94af14e5b825a5bae769b0.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值