赞
踩
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http:// e u r e k a . i n s t a n c e . h o s t n a m e : {eureka.instance.hostname}: eureka.instance.hostname:{server.port}/eureka/
#相当于:http://localhost:7001/eureka/
(4)编写Spring Boot启动器
注意:要在主启动器上方添加 @EnableEurekaServer表示 服务端的启动类,可以接受别人注册进来
package com.yixin.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer_7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer_7001.class,args);
}
}
(5)启动并访问http://localhost:7001/
页面出现如下,表示成功!
4.3 配置springcloud-provider-blog-8001
(1)建立以下目录
(2)编写pom.xml
org.springframework.cloud
spring-cloud-starter-eureka
1.4.6.RELEASE
org.springframework.boot
spring-boot-test
2.4.5
org.springframework.boot
spring-boot-starter-web
2.4.5
org.springframework.boot
spring-boot-devtools
(3)编写 application.yml
server:
port: 8001
spring:
application:
name: springcloud-provider-blog
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
(4)编写启动类
注意:要为主启动类添加@EnableEurekaClient注解
package com.yixin.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
public class BlogProvider_8001 {
public static void main(String[] args) {
SpringApplication.run(BlogProvider_8001.class,args);
}
}
(5)启动测试
依次启动:
服务端:springcloud-eureka-7001------>客户端:springcloud-provider-blog-8001
访问监控页:http://localhost:7001/
可以发现,eureka已经成功将我们的客户端注册进去了。
可以发现如果我们不对其描述信息进行描述,Eureka会采用默认的描述方式
(1)修改默认描述信息
修改springcloud-provider-blog-8001下的application.yml
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
instance:
insta
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。