SpringCloud Eureka Server 启动报错,无法启动问题解决

r囧r小猫 2023-01-17 10:56 526阅读 0赞

SpringCloud Eureka报错启动不了大多数是因为依赖问题,springboot的版本和springcloud的版本需要进行匹配,可以参考SpringCloud官网配置,千万不要自己瞎配。

不然可能就会出现以下各种报错:
在这里插入图片描述
在这里插入图片描述
我们可以看下官方给出的示例:

  1. <!-- maven仓库 -->
  2. <repositories>
  3. <repository>
  4. <id>spring-milestones</id>
  5. <name>Spring Milestones</name>
  6. <url>https://repo.spring.io/milestone</url>
  7. <snapshots>
  8. <enabled>false</enabled>
  9. </snapshots>
  10. </repository>
  11. </repositories>
  12. <!-- 依赖管理 -->
  13. <dependencyManagement>
  14. <dependencies>
  15. <dependency>
  16. <groupId>org.springframework.cloud</groupId>
  17. <artifactId>spring-cloud-dependencies</artifactId>
  18. <version>2020.0.0-M5</version>
  19. <type>pom</type>
  20. <scope>import</scope>
  21. </dependency>
  22. </dependencies>
  23. </dependencyManagement>
  24. <dependencies>
  25. <!-- eureka-server -->
  26. <dependency>
  27. <groupId>org.springframework.cloud</groupId>
  28. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  29. <!-- 这里不要给指定版本号,SpringCloud所有依赖包都交由spring-cloud-dependencies统一管理 -->
  30. </dependency>
  31. </dependencies>

然后我们看官网说的,该版本它依赖于SpringBoot的2.4.0版本
在这里插入图片描述
最后给出我的依赖配置如下:
父工程依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <parent>
  5. <groupId>org.springframework.boot</groupId>
  6. <artifactId>spring-boot-starter-parent</artifactId>
  7. <version>2.4.0</version>
  8. <relativePath/> <!-- lookup parent from repository -->
  9. </parent>
  10. <groupId>com.example</groupId>
  11. <artifactId>springcloud-demo</artifactId>
  12. <version>0.0.1-SNAPSHOT</version>
  13. <name>springcloud-demo</name>
  14. <description>Demo project for Spring Boot</description>
  15. <modules>
  16. <module>service-eureka</module>
  17. </modules>
  18. <properties>
  19. <java.version>1.8</java.version>
  20. <spring-cloud.version>2020.0.0-M5</spring-cloud.version>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-test</artifactId>
  30. </dependency>
  31. </dependencies>
  32. <build>
  33. <plugins>
  34. <plugin>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-maven-plugin</artifactId>
  37. </plugin>
  38. </plugins>
  39. <finalName>springCloud-demo</finalName>
  40. </build>
  41. <dependencyManagement>
  42. <dependencies>
  43. <dependency>
  44. <groupId>org.springframework.cloud</groupId>
  45. <artifactId>spring-cloud-dependencies</artifactId>
  46. <version>${spring-cloud.version}</version>
  47. <type>pom</type>
  48. <scope>import</scope>
  49. </dependency>
  50. </dependencies>
  51. </dependencyManagement>
  52. <repositories>
  53. <repository>
  54. <id>spring-milestones</id>
  55. <name>Spring Milestones</name>
  56. <url>https://repo.spring.io/milestone</url>
  57. </repository>
  58. </repositories>
  59. </project>

子工程eureka依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <parent>
  5. <groupId>com.example</groupId>
  6. <artifactId>springcloud-demo</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. </parent>
  9. <groupId>com.example</groupId>
  10. <artifactId>service-eureka</artifactId>
  11. <version>0.0.1-SNAPSHOT</version>
  12. <name>service-eureka</name>
  13. <description>Demo project for Spring Boot</description>
  14. <properties>
  15. <java.version>1.8</java.version>
  16. </properties>
  17. <dependencies>
  18. <dependency>
  19. <groupId>org.springframework.cloud</groupId>
  20. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  21. </dependency>
  22. </dependencies>
  23. <build>
  24. <plugins>
  25. <plugin>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-maven-plugin</artifactId>
  28. </plugin>
  29. </plugins>
  30. </build>
  31. </project>

发表评论

表情:
评论列表 (有 0 条评论,526人围观)

还没有评论,来说两句吧...

相关阅读