簡體   English   中英

添加spring-boot-starter-web時Spring Boot App啟動時出錯

[英]Error on Spring Boot App Startup when adding spring-boot-starter-web

使用spring-cloud-starter-aws-secrets-manager-config啟動一個非常基本的Spring boot應用程序以檢索AWS sectrets可以正常工作。 但是,當我將spring-boot-starter-web dependency到項目中以提供Web服務支持時, the spring-cloud-starter-aws-secrets-manager-config errors導致應用程序無法啟動。

pom.xml

<?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 http://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>1.5.6.RELEASE</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>1.8</java.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</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-aws-secrets-manager-config</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
<!-- if I remove spring-boot-starter-web it all starts properly -->
                <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

爪哇

package com.secrets.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class App
{

    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }

}

bootstrap.yml

spring:
  application:
    name: app_name
aws:
  secretsmanager:
    prefix: /secret
    defaultContext: application
    profileSeparator: _
    failFast: true
    name: app_name
    enabled: true

應用程序應正常啟動,但是應用程序出現以下錯誤:

啟動ApplicationContext時出錯。 要顯示自動配置報告,請在啟用“調試”的情況下重新運行您的應用程序。 2019-07-03 11:57:16.563錯誤73839 --- [main] osboot.SpringApplication:應用程序啟動失敗

org.springframework.beans.factory.UnsatisfiedDependencyException:創建名稱為'propertySourceBootstrapConfiguration'的bean時出錯:通過字段'propertySourceLocators'表示的不滿足的依賴關系; 嵌套的異常是org.springframework.beans.factory.UnsatisfiedDependencyException:創建名稱為“ awsSecretsManagerPropertySourceLocator”的Bean時出錯,該名稱在org.springframework.cloud.aws.autoconfigure.secretsmanager.AwsSecretsManagerBootstrapConfiguration中定義。 嵌套的異常是org.springframework.beans.factory.BeanCreationException:創建名稱為“ aws.secretsmanager-org.springframework.cloud.aws.secretsmanager.AwsSecretsManagerProperties”的bean時出錯:無法將屬性綁定到AwsSecretsManagerProperties(prefix = aws.secretsFieldManager,忽略= false,ignoreUnknownFields = true,ignoreNestedProperties = false); 嵌套的異常是org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)上的java.lang.NullPointerException〜〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE ]在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory .annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapable java:1264)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)〜[spring-beans -4.3.10.RELEASE.jar:4.3.10.RELEASE],網址為 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory.support .AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java :230)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans- 4.3.10.RELEASE.jar:4.3.10.RELEASE],位於org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.10.RELEASE.jar:4.3 .10.RELEASE],位於org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)〜[spring-beans-4.3.10.RELEASE.jar:4.3.10.R ELEASE]位於org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]位於org.springframework.context.support。 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)上的AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] [spring-於org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)的boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] [spring-boot-1.5.6.RELEASE.jar:1.5.6。 RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:303)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]在org.springframework.boot.builder.SpringApplicationBuilder.run (SpringApplicationBuilder.java:134)在org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicat)上的[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] ionListener.java:187)[spring-cloud-context-1.3.2.RELEASE.jar:1.3.2.RELEASE]在org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)[spring-cloud -context-1.3.2.RELEASE.jar:1.3.2.RELEASE]在org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)[spring-cloud-context-1.3.2.RELEASE.jar :1.3.2.RELEASE],位於org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE],位於org.springframework。 context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java: 122)[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]在org.springframew ork.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE],位於org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners。 java:54)位於org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)的[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE] [spring-boot-1.5.6.RELEASE .org:1.5.6.RELEASE]位於org.springframework.boot.SpringApplication.run(SpringApplication.java:296)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]位於org.springframework。 boot.SpringApplication.run(SpringApplication.java:1118)[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)[spring -boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]位於com.secrets.demo.App.main(App.java:13)[classes /:na]

您正在混合1.5.x和2.x依賴項。 由於這兩個版本之間存在重大更改,因此在同一項目中同時使用這兩個版本時,經常會出現兼容性問題。

由於spring-cloud-starter-aws-secrets-manager-config僅支持2.x,因此您需要將spring boot starter parent升級到2.x版本。

@Michael McFadyen的回復是正確的; 但是,值得注意的是,手動添加Spring Cloud依賴及其版本不是一個好習慣。 應該改用dependencyManagement插件和Spring Cloud Release火車,以確保使用的所有Spring Cloud庫都處於兼容版本中。請參閱項目頁面中的“發行火車”部分。 它還包含有關哪些發行版與哪個Spring Boot版本相對應的信息。

如果要確保在構建文件中正確設置了Spring依賴項,則可以轉到start.spring.io生成具有正確構建文件的項目存根。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM