第一步创建工程
1、选择File,然后new 再然后Project
2、填写项目信息,然后下一步
3、选择依赖 Spring Cloud Discovery 然后选择Eureka Discovery Client ,然后下一步
4、选择文件位置,然后Finish就行
第二步、启动类添加 @EnableEurekaClient 标签
1 package com.ssc.eureka_provide; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 7 @EnableEurekaClient 8 @SpringBootApplication 9 public class EurekaProvideApplication { 10 11 public static void main(String[] args) { 12 SpringApplication.run(EurekaProvideApplication.class, args); 13 } 14 15 }
第三步新建一个类,提供服务接口
1 package com.ssc.eureka_provide; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 7 @EnableEurekaClient 8 @SpringBootApplication 9 public class EurekaProvideApplication { 10 11 public static void main(String[] args) { 12 SpringApplication.run(EurekaProvideApplication.class, args); 13 } 14 15 }
第四步、application.yml添加配置
1 spring: 2 application: 3 name: eureka-user-provide 4 server: 5 port: 8055 6 eureka: 7 client: 8 service-url: 9 defaultZone: http://localhost:8761/eureka 10 instance: 11 prefer-ip-address: true 12 instance-id: ${spring.application.name}:${eureka.instance.prefer-ip-address}:${server.port}
第五步、启动服务查看Eureka Server注册信息,前提Eureka Server需要是启动的