Ошибка при запуске Spring Boot App при добавлении spring-boot-starter-web - PullRequest
0 голосов
/ 03 июля 2019

Запуск очень простого Spring boot приложения с использованием spring-cloud-starter-aws-secrets-manager-config для получения AWS sectrets работает правильно. Однако, как только я добавляю spring-boot-starter-web dependency в проект для поддержки веб-службы, 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>

Java

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 --- [главная] o.s.boot.SpringApplication: сбой запуска приложения

org.springframework.beans.factory.UnsatisfiedDependencyException: Ошибка создания бина с именем propertySourceBootstrapConfiguration: Неудовлетворенная зависимость выражается через поле 'propertySourceLocators'; вложенное исключение org.springframework.beans.factory.UnsatisfiedDependencyException: Ошибка создания бина с именем 'awsSecretsManagerPropertySourceLocator' определяется в org.springframework.cloud.aws.autoconfigure.secretsmanager.AwsSecretsManagerBootstrapConfiguration: Неудовлетворенная зависимость выражается методом параметр «awsSecretsManagerPropertySourceLocator» 1; вложенное исключение isg.springframework.beans.factory.BeanCreationException: ошибка создание бина с именем 'aws.secretsmanager-org.springframework.cloud.aws.secretsmanager.AwsSecretsManagerProperties': Не удалось связать свойства с AwsSecretsManagerProperties (prefix = aws.secretsmanager, ignoreInvalidFields = false, ignoreUnknownFields = true, ignoreNestedProperties = false); вложенными исключение java.lang.NullPointerException в org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject (AutowiredAnnotationBeanPostProcessor.java:588) ~ [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 (AbstractAutowireCapableBeanFactory.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.RELEASE] в org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:867)~ [spring-context-4.3.10.RELEASE.jar: 4.3.10.RELEASE] в org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:543) ~ [spring-context-4.3.10.RELEASE.jar: 4.3.10.RELEASE] в org.springframework.boot.SpringApplication.refresh (SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar: 1.5.6.RELEASE] в org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:360) [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) [spring-boot-1.5.6.RELEASE.jar: 1.5.6.RELEASE] в org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext (BootstrapApplicationListener.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] в org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster.java:122) [spring-context-4.3.10.RELEASE.jar: 4.3.10.RELEASE] в org.springframework.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) [spring-boot-1.5.6.RELEASE.jar: 1.5.6.RELEASE] в org.springframework.boot.SpringApplication.prepareEnvironment (SpringApplication.java:325) [spring-boot-1.5.6.RELEASE.jar: 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) [классы /: нет]

Ответы [ 2 ]

1 голос
/ 04 июля 2019

@ Майкл МакФадьен ответил правильно;однако стоит также отметить, что ручное добавление зависимостей Spring Cloud и их версий не является хорошей практикой.Вместо этого следует использовать плагин dependencyManagement и последовательности Spring Cloud Release, чтобы гарантировать, что все используемые библиотеки Spring Cloud находятся в совместимых версиях. См. Раздел «Release Trains» на странице проекта .Он также содержит информацию о том, какие поезда выпуска соответствуют каким версиям Spring Boot.

Если вы хотите убедиться, что вы правильно настраиваете зависимости Spring в своем файле сборки, вы можете перейти на start.spring.io , чтобы сгенерировать заглушку проекта с правильным файлом сборки..

1 голос
/ 04 июля 2019

Вы смешиваете зависимости 1.5.x и 2.x.Поскольку между этими двумя версиями происходят серьезные изменения, часто возникают проблемы совместимости при использовании обоих в одном и том же проекте.

Поскольку spring-cloud-starter-aws-secrets-manager-config поддерживает только 2.x, вам нужно обновить родительский загрузочный весенний загрузчик до версии 2.x.

...