今天啟動用eureka的服務消費者時,一直出現問題。
SpringCloud報錯:
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
解決方案:
網上的解決方案大多如下:
1.在main()方法的啟動類的上方添加注解 @SpringBootApplication
2.可能是pom.xml中缺少依賴包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
這些並沒有解決我的問題,檢查了幾個小時后,發現是我的 .class 文件名稱寫錯了。這個錯誤太低級了。。
將.class名稱改為與類名一致就可以了。
@SpringBootApplication @EnableDiscoveryClient public class EurekaConsumerApplication { public static void main(String[] args) { new SpringApplicationBuilder(EurekaConsumerApplication.class).web(true).run(args); } }