1.在父项目中导入SpringCloud版本依赖
org.springframework.cloud spring-cloud-dependenciesHoxton.SR12 pom import
1.1在eureka子项目中导入依赖,我用的是jetty云服务,在性能,资源上更有优势.
org.springframework.cloud spring-cloud-starter-netflix-eureka-serverorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-tomcatorg.springframework.boot spring-boot-starter-jetty
2.在eureka子项目的resources目录中新建application.yml配置文件
server:
port: 7001
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
register-with-eureka: false # 是否要注册到eureka
fetch-registry: false # 自身不去获取服务注册信息
3.编写启动类,在网页上输入localhost:7001就能查看了
@SpringBootApplication
@EnableEurekaServer // 开启服务注册功能
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class);
}
}
4.补充:哪一个服务如果想注册eureka必须添加依赖
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
4.1然后在application.yml中添加配置
spring:
application:
name: hello-provider #服务名称
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
register-with-eureka: true # 是否要注册到eureka
fetch-registry: false # 自身不去获取服务注册信息
4.2在启动类上加上@EnableEurekaClient注解,标识当前应用是eureka的客户端



