【问题标题】:Gradle + Spring Boot Error: Failed to bind propertiesGradle + Spring Boot 错误:无法绑定属性
【发布时间】:2021-11-11 02:46:25
【问题描述】:

我正在从 Maven 迁移到 Gradle,当通过 Gradle 生成的 jar 文件运行时,Spring 引导服务无法启动。该应用程序作为 Spring 应用程序或作为通过 maven 生成的 jar 运行时运行良好。 我有一种感觉,我们在 Gradle 中缺少一些依赖项,但无法解决。感谢有人能指出我所缺少的。

错误:

{"timestamp":"2021-09-15 03:37:23 UTC","message":"Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory'
defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servletWebServerFactoryCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.class]: Unsatisfied dependency expressed through method 'servletWebServerFactoryCustomizer' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'server-org.springframework.boot.autoconfigure.web.ServerProperties': Could not bind properties to 'ServerProperties' : prefix=server, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'server.error.include-stacktrace' to org.springframework.boot.autoconfigure.web.ErrorProperties$IncludeAttribute","thread":"main","logLevel":"WARN","fileName":"AbstractApplicationContext.java","line":591,"serviceCode":"SMPL-JAVA-MS"}
{"timestamp":"2021-09-15 03:37:23 UTC","message":"\n\nError starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.","thread":"main","logLevel":"INFO","fileName":"ConditionEvaluationReportLoggingListener.java","line":136,"serviceCode":"SMPL-JAVA-MS"}

Gradle 依赖项

  implementation 'org.modelmapper:modelmapper:2.4.2'
  implementation 'org.springframework.boot:spring-boot-starter-web:+'
  implementation 'org.springframework.boot:spring-boot-starter-validation:+'
  implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:+'
  implementation 'io.springfox:springfox-swagger2:3.0.0'
  implementation 'io.springfox:springfox-swagger-ui:3.0.0'
  implementation 'io.springfox:springfox-boot-starter:3.0.0'
  implementation 'org.springframework.boot:spring-boot-starter-webflux:+'
  implementation 'org.opensaml:opensaml:2.5.1-1'
  implementation 'org.springframework.boot:spring-boot-starter-data-jpa:+'
  implementation 'org.springframework.boot:spring-boot-starter-test:+'
  implementation 'com.google.guava:guava:30.1.1-jre'
  runtimeOnly 'org.projectlombok:lombok:1.18.20'
  runtimeOnly 'org.postgresql:postgresql:+'
  runtimeOnly 'org.springframework.boot:spring-boot-devtools:+'
  testImplementation 'org.springframework.boot:spring-boot-starter-test:+'

痘.xml

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.3</version>
    <relativePath />
  </parent>

  <groupId>***</groupId>
  <artifactId>***</artifactId>
  <version>1.0.0</version>
  <name>***</name>
  <description>***</description>

  <properties>
    <java.version>16</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.20</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.modelmapper</groupId>
      <artifactId>modelmapper</artifactId>
      <version>2.4.2</version>
    </dependency>
    <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.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-xml</artifactId>
    </dependency>

    <!-- swagger UI at http://localhost:8080/swagger-ui/index.html -->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>3.0.0</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>3.0.0</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
      <version>3.0.0</version>
    </dependency>

    <!-- Web Client for accessing external requests -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
      <groupId>org.opensaml</groupId>
      <artifactId>opensaml</artifactId>
      <version>2.5.1-1</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>30.1.1-jre</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>
  </dependencies>

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

【问题讨论】:

  • 能否请您提供 maven 依赖项,以便我们可以尝试相同?
  • 如果没有pom.xml 和完整的build.gradle,这将无法回答。我注意到的一件事是该版本的+,它们不应该存在,并且您将spring-boot-starter-test 作为测试和实现依赖项(应该仅用于测试)。
  • @Supritam 我已经用 pom.xml 内容更新了我的 Q。并且删除 spring-boot-starter-test 重复条目并没有帮助。

标签: java spring spring-boot maven gradle


【解决方案1】:

发现问题。原来是我的application.properties 文件中已弃用的属性。这需要去:

server.error.include-stacktrace=ON_TRACE_PARAM

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 2018-08-22
    • 1970-01-01
    • 2019-03-26
    • 2016-02-27
    相关资源
    最近更新 更多