Skip to content

Commit 1197cae

Browse files
成功启动eureka-consumer
1 parent 5496e91 commit 1197cae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

eureka-client/src/main/java/com/example/demo/controller/DcController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.web.bind.annotation.RequestMethod;
1111
import org.springframework.web.bind.annotation.RestController;
1212

13+
import java.util.List;
14+
1315
/**
1416
* Created by lenovo on 九月
1517
*/
@@ -24,6 +26,10 @@ public class DcController {
2426
@GetMapping("/dc")
2527
public String dc( ) {
2628
ServiceInstance serviceInstance=discoveryClient.getLocalServiceInstance();
29+
List<String> serviceList=discoveryClient.getServices();
30+
for(String service : serviceList) {
31+
System.out.println("Service:"+ service );
32+
}
2733
System.out.println( "ServiceHost:"+ serviceInstance.getHost() );
2834
return "service";
2935
}

readMe.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
"Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found."
44
解决方案: Discovery的包有两个,导入org.springframework.cloud.client.discovery.DiscoveryClient才是正确的。 <br>
55
2. new SpringApplicationBuilder(EurekaClientApplication.class).web(true).run(args);和默认生成的 main方法 有什么区别 ? <br>
6-
3.Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
6+
3.启动eureka-consumer报错如下: <br>
7+
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.<br>
8+
解决方案: 启动类上方添加@SpringBootApplication。另外,还要注意启动类中的 .class文件名称是否与类名一致。<br>
9+
new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args);
10+

0 commit comments

Comments
 (0)