Skip to content

Commit 31731db

Browse files
配置中心Config的客户端一直无法获取配置
1 parent 10c20e6 commit 31731db

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.demo.Controller;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
/**
8+
* Created by lenovo on 九月
9+
*/
10+
@RestController
11+
public class ConfigController {
12+
13+
@Value("${ foo }")
14+
private String name;
15+
16+
17+
@GetMapping(value = "/name")
18+
public String name(){
19+
return "hello"+name ;
20+
}
21+
}

config-client/src/main/resources/application.properties

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server:
2+
port: 3002
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
spring:
22
application:
33
name: config-client
4-
54
cloud:
65
config:
7-
uri: http://localhost:3001/
8-
profile: default
6+
uri: http://localhost:3001/
7+
profile: dev
98
label: master
109

1110

12-
server:
13-
port: 3002
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
spring.application.name= config-server
22

3-
spring.cloud.config.server.git.uri=http://git.oschina.net/didispace/config-repo-demo/
4-
3+
#spring.cloud.config.server.git.uri=http://git.oschina.net/didispace/config-repo-demo/
4+
spring.cloud.config.server.git.uri=https://github.com/forezp/SpringcloudConfig/
5+
# searchPaths配置仓库路径
6+
spring.cloud.config.server.git.searchPaths=respo
7+
#配置仓库分支
8+
spring.cloud.config.label=master
59
server.port=3001

readMe.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
一、遇到的问题 <br>
22
1.eureka-client中的DiscoveryClient一直报错 <br>
3-
"Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found."
3+
"Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found." <br>
44
解决方案: Discovery的包有两个,导入org.springframework.cloud.client.discovery.DiscoveryClient才是正确的。 <br>
55
2. new SpringApplicationBuilder(EurekaClientApplication.class).web(true).run(args);和默认生成的 main方法 有什么区别 ? <br>
66
3.启动eureka-consumer报错如下: <br>
77
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.<br>
88
解决方案: 启动类上方添加@SpringBootApplication。另外,还要注意启动类中的 .class文件名称是否与类名一致。<br>
9-
new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args);
9+
new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args); <br>
1010
4.启动Ribbon进行服务消费,报错:
1111
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server <br>
12-
解决方案; 修正 eureka.client.service-url.defaultZone .
12+
解决方案; 修正 eureka.client.service-url.defaultZone . <br>
13+
5.分布式配置中心。访问的url格式有多样。可以是localhost://application/profile/label,也可以是其他 <br>
14+
访问Config服务端,http://localhost:3001/config-client/dev/masterhttp://localhost:3001/config-client/lin/master的内容不一样?
15+
为什么profile只有设定为dev才可以查看config-client-dev.yml的内容。 <br>
16+
解决方案: 在spring.cloud.config.profile 这个配置中, dev表示开发环境配置文件、test表示测试环境、pro表示正式环境
17+
6.分布式Config中,客户端无法访问服务端配置中心。如何破解?

0 commit comments

Comments
 (0)