出错点:1.找不到文件,设置dev,profile,lable,searchpaths(包名,没有测试过) ,另外注意git中的命名规则必须和springboot中的一致
2.设置注解问题,EnableEurekaClient,@RefreshScope,@EnableConfigServer
3.高可用注册中心不能使用localhost作为名字!!! ,主机名都必须在etc/host包中进行注册
@
config-server:
server:
port: 8768
spring:
application:
name: config-server
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
cloud:
config:
server:
git:
uri: https://github.com/1445023633/MyRepository
username: 1445023633
password: AIni1314
label: master
default-profile: dev
# search-paths:
# - problem.yml
eureka:
client:
service-url:
default-zone: http://localhost:8761/eureka/
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId> (总线核心)
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> (启动核心)
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId> (核心)
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
··················
config-client:
application.yml:
eureka:
client:
service-url:
default-zone: http://localhost:8761/eureka/
server:
port: 8769
spring:
application:
name: config-client
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
management:
security:
enabled: false
`````
bootstrap.yml:
spring:
cloud:
config:
profile: dev #profile一定要,不然找不到git中的文件
discovery:
enabled: true (必须开启可以寻找)
service-id: config-server (核心,为配置中心的名字)
label: master (分支)
···
@EnableEurekaClient
//@EnableDiscoveryClient (暂时不要)
@SpringBootApplication
@RefreshScope (总线核心配合rabbitMq)
@Value("${hello}") //配置服务器中的文件必须符合命名规则,否则会找不到文件参数!!!
String hello;
@RequestMapping("/lucky-word")
public String showLuckyWord() {
System.out.println(hello);
return "The lucky word is: " + hello;
}
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId> (核心,和clientServer区分开来)
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- 消息总线要用的 -->
<dependency>
<groupId>org.springframework.retry</groupId> (核心,需要查)
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId> (核心)
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> (核心)
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> (为后面准备)
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId> (不知道什么时候要使用,用了反而报错,需要查一下)
</dependency> -->
springcloud config-server&config-client
猜你喜欢
转载自blog.csdn.net/qq_27988103/article/details/79869391
今日推荐
周排行