【问题标题】:Error creating bean with name 'configurationPropertiesBeans'创建名为“configurationPropertiesBeans”的 bean 时出错
【发布时间】:2021-11-06 10:36:32
【问题描述】:

我正在使用 Netflix Zuul 代理创建一个非常基本的 SpringBoot 应用程序。我在启动过程中收到此错误。我关注了另一个关于类似错误的 StackOverflow 线程,我意识到 Spring Web 和 Spring Cloud 依赖项之间存在兼容性问题。如果有人能说出这个 pom 文件的匹配版本应该是什么,我将不胜感激?

  • spring-boot-maven-plugin - 2.3.4.RELEASE
  • spring-cloud-starter-netflix-zuul - 2.2.9.RELEASE
  • spring-boot-starter-test - 2.5.4
  • spring-boot-starter-web - 2.5.4
<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>HospitalGatewayService</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>HospitalGatewayService</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

  • zuul与boot 2.4-2.5不兼容,只能2.3

标签: spring-boot spring-mvc spring-cloud netflix-zuul


【解决方案1】:

请注意,Zuul 已被 Spring Cloud Gateway 取代,因此如果您想保留当前的 ​​spring-boot 版本2.5.4,您将不得不切换到 Gateway 项目。

Spring Initializr (https://start.spring.io/) 生成的pom.xml 选择依赖项“Spring Web”和“Gateway”,用于 spring-boot 版本2.5.4 如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【讨论】:

    【解决方案2】:

    我经常做的事情,每当我使用spring时,我都会使用spring依赖管理来决定版本,而不是手动输入版本。

    该插件将控制项目依赖项的版本,并将遵守项目依赖项的 pom 中声明的任何排除项。

    如果需要,它还允许您覆盖。

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2021-11-28
      • 2020-10-03
      • 2019-08-28
      • 2015-03-18
      • 2021-03-17
      • 2021-06-18
      • 2019-07-21
      • 2016-04-04
      相关资源
      最近更新 更多