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

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1、新建maven项目

2、引入jar依赖



	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、启动,观察注册中心

SpringCloud使用eureka注册服务(提供接口)_第1张图片

 

SpringCloud使用eureka注册服务(提供接口)_第2张图片

 

 

 

 

 

 

转载于:https://my.oschina.net/xiaozhiwen/blog/1842406

你可能感兴趣的:(SpringCloud使用eureka注册服务(提供接口))