File tree 6 files changed +39
-10
lines changed
java/com/example/demo/Controller
config-server-git/src/main/resources
6 files changed +39
-10
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ server :
2
+ port : 3002
Original file line number Diff line number Diff line change 1
1
spring :
2
2
application :
3
3
name : config-client
4
-
5
4
cloud :
6
5
config :
7
- uri : http://localhost:3001/
8
- profile : default
6
+ uri : http://localhost:3001/
7
+ profile : dev
9
8
label : master
10
9
11
10
12
- server :
13
- port : 3002
Original file line number Diff line number Diff line change 1
1
spring.application.name = config-server
2
2
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
5
9
server.port =3001
Original file line number Diff line number Diff line change 1
1
一、遇到的问题 <br >
2
2
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 >
4
4
解决方案: Discovery的包有两个,导入org.springframework.cloud.client.discovery.DiscoveryClient才是正确的。 <br >
5
5
2 . new SpringApplicationBuilder(EurekaClientApplication.class).web(true).run(args);和默认生成的 main方法 有什么区别 ? <br >
6
6
3.启动eureka-consumer报错如下: <br >
7
7
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.<br >
8
8
解决方案: 启动类上方添加@SpringBootApplication 。另外,还要注意启动类中的 .class文件名称是否与类名一致。<br >
9
- new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args);
9
+ new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args); < br >
10
10
4.启动Ribbon进行服务消费,报错:
11
11
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/master 跟 http://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中,客户端无法访问服务端配置中心。如何破解?
You can’t perform that action at this time.
0 commit comments