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