Spring Cloud 2020.0 不再处理 bootstrap.yml 配置

2024-03-21

In my Spring Boot 项目 https://github.com/pavankjadda/HashiCorpVault-SpringCloud,我定义了4个配置文件

  1. demo
  2. dev
  3. test
  4. prod

在启动过程中,YAML 文件中的属性将被 HashiCorp Vault 属性替换。为此,我使用 Spring Cloud Vault 库。 Spring Boot 2.3.x 中一切都按预期工作

当我尝试使用 Spring Cloud Vault 3.0.0-SNAPSHOT 版本将项目升级到 Spring Boot 2.4.0 时,属性没有被替换

bootstrap.yml

spring:
  cloud:
    vault:
      authentication: APPROLE
      app-role:
        role-id: ${role-id}
        secret-id: ${secret-id}
        role: pres-read
        app-role-path: approle
      uri: ${vault-server}
      connection-timeout: 5000
      read-timeout: 15000
      kv:
        enabled: true
        backend: secret
        application-name: app/pres

应用程序.yml

spring:
  config:
    activate:
      on-profile: 'demo'

应用程序演示.yml

## Server Properties
server:
  port: 8081

spring:
  datasource:
    username: ${pres.db.username}
    password: ${pres.db.password}
    url: ${pres.db.url}

Spring Cloud Vault 库

      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-vault-config</artifactId>
            <version>3.0.0-SNAPSHOT</version>
        </dependency>

错误日志:

/Users/jaddap2/Library/Java/JavaVirtualMachines/adopt-openj9-11.0.9/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59487,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.profiles.active=demo -Dspring.output.ansi.enabled=always -Drole_id=49c8d8fb-1bdd-7f3b-493f-a11e20907a62 -Dsecret_id=a7ee91cc-e259-82ff-2b34-5c333dda300c -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:/Users/jaddap2/Library/Caches/JetBrains/IntelliJIdea2020.2/captureAgent/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath /Users/jaddap2/IdeaProjects/HashiCorpVault-SpringCloud/target/classes:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/2.4.0/spring-boot-starter-data-jpa-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-aop/2.4.0/spring-boot-starter-aop-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-aop/5.3.1/spring-aop-5.3.1.jar:/Users/jaddap2/.m2/repository/org/aspectj/aspectjweaver/1.9.6/aspectjweaver-1.9.6.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/2.4.0/spring-boot-starter-jdbc-2.4.0.jar:/Users/jaddap2/.m2/repository/com/zaxxer/HikariCP/3.4.5/HikariCP-3.4.5.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-jdbc/5.3.1/spring-jdbc-5.3.1.jar:/Users/jaddap2/.m2/repository/jakarta/transaction/jakarta.transaction-api/1.3.3/jakarta.transaction-api-1.3.3.jar:/Users/jaddap2/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar:/Users/jaddap2/.m2/repository/org/hibernate/hibernate-core/5.4.23.Final/hibernate-core-5.4.23.Final.jar:/Users/jaddap2/.m2/repository/org/jboss/logging/jboss-logging/3.4.1.Final/jboss-logging-3.4.1.Final.jar:/Users/jaddap2/.m2/repository/org/javassist/javassist/3.24.0-GA/javassist-3.24.0-GA.jar:/Users/jaddap2/.m2/repository/net/bytebuddy/byte-buddy/1.10.18/byte-buddy-1.10.18.jar:/Users/jaddap2/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/jaddap2/.m2/repository/org/jboss/jandex/2.1.3.Final/jandex-2.1.3.Final.jar:/Users/jaddap2/.m2/repository/com/fasterxml/classmate/1.5.1/classmate-1.5.1.jar:/Users/jaddap2/.m2/repository/org/dom4j/dom4j/2.1.3/dom4j-2.1.3.jar:/Users/jaddap2/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar:/Users/jaddap2/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.3/jaxb-runtime-2.3.3.jar:/Users/jaddap2/.m2/repository/org/glassfish/jaxb/txw2/2.3.3/txw2-2.3.3.jar:/Users/jaddap2/.m2/repository/com/sun/istack/istack-commons-runtime/3.0.11/istack-commons-runtime-3.0.11.jar:/Users/jaddap2/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar:/Users/jaddap2/.m2/repository/org/springframework/data/spring-data-jpa/2.4.1/spring-data-jpa-2.4.1.jar:/Users/jaddap2/.m2/repository/org/springframework/data/spring-data-commons/2.4.1/spring-data-commons-2.4.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-orm/5.3.1/spring-orm-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-context/5.3.1/spring-context-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-tx/5.3.1/spring-tx-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-beans/5.3.1/spring-beans-5.3.1.jar:/Users/jaddap2/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-aspects/5.3.1/spring-aspects-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-web/2.4.0/spring-boot-starter-web-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter/2.4.0/spring-boot-starter-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.4.0/spring-boot-starter-logging-2.4.0.jar:/Users/jaddap2/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/Users/jaddap2/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/Users/jaddap2/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.3/log4j-to-slf4j-2.13.3.jar:/Users/jaddap2/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.3/log4j-api-2.13.3.jar:/Users/jaddap2/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/Users/jaddap2/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/jaddap2/.m2/repository/org/yaml/snakeyaml/1.27/snakeyaml-1.27.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-json/2.4.0/spring-boot-starter-json-2.4.0.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.3/jackson-databind-2.11.3.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.11.3/jackson-annotations-2.11.3.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.3/jackson-core-2.11.3.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.11.3/jackson-datatype-jdk8-2.11.3.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.11.3/jackson-datatype-jsr310-2.11.3.jar:/Users/jaddap2/.m2/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.11.3/jackson-module-parameter-names-2.11.3.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/2.4.0/spring-boot-starter-tomcat-2.4.0.jar:/Users/jaddap2/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.39/tomcat-embed-core-9.0.39.jar:/Users/jaddap2/.m2/repository/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar:/Users/jaddap2/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/9.0.39/tomcat-embed-websocket-9.0.39.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-web/5.3.1/spring-web-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-webmvc/5.3.1/spring-webmvc-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-expression/5.3.1/spring-expression-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/cloud/spring-cloud-starter-vault-config/3.0.0-SNAPSHOT/spring-cloud-starter-vault-config-3.0.0-20201123.200715-420.jar:/Users/jaddap2/.m2/repository/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar:/Users/jaddap2/.m2/repository/commons-codec/commons-codec/1.15/commons-codec-1.15.jar:/Users/jaddap2/.m2/repository/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13.jar:/Users/jaddap2/.m2/repository/org/springframework/cloud/spring-cloud-starter/3.0.0-SNAPSHOT/spring-cloud-starter-3.0.0-20201123.160603-486.jar:/Users/jaddap2/.m2/repository/org/springframework/cloud/spring-cloud-context/3.0.0-SNAPSHOT/spring-cloud-context-3.0.0-20201123.160522-488.jar:/Users/jaddap2/.m2/repository/org/springframework/security/spring-security-crypto/5.4.1/spring-security-crypto-5.4.1.jar:/Users/jaddap2/.m2/repository/org/springframework/cloud/spring-cloud-commons/3.0.0-SNAPSHOT/spring-cloud-commons-3.0.0-20201123.160533-486.jar:/Users/jaddap2/.m2/repository/org/springframework/security/spring-security-rsa/1.0.9.RELEASE/spring-security-rsa-1.0.9.RELEASE.jar:/Users/jaddap2/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.64/bcpkix-jdk15on-1.64.jar:/Users/jaddap2/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.64/bcprov-jdk15on-1.64.jar:/Users/jaddap2/.m2/repository/org/springframework/cloud/spring-cloud-vault-config/3.0.0-SNAPSHOT/spring-cloud-vault-config-3.0.0-20201123.200557-420.jar:/Users/jaddap2/.m2/repository/org/springframework/vault/spring-vault-core/2.3.0-M1/spring-vault-core-2.3.0-M1.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-devtools/2.4.0/spring-boot-devtools-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot/2.4.0/spring-boot-2.4.0.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.4.0/spring-boot-autoconfigure-2.4.0.jar:/Users/jaddap2/.m2/repository/mysql/mysql-connector-java/8.0.22/mysql-connector-java-8.0.22.jar:/Users/jaddap2/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/2.4.0/spring-boot-configuration-processor-2.4.0.jar:/Users/jaddap2/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar:/Users/jaddap2/.m2/repository/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/Users/jaddap2/.m2/repository/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-core/5.3.1/spring-core-5.3.1.jar:/Users/jaddap2/.m2/repository/org/springframework/spring-jcl/5.3.1/spring-jcl-5.3.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar com.pj.vaultdemo.VaultDemoApplication
Connected to the target VM, address: '127.0.0.1:59487', transport: 'socket'
{spring.web.resources.chain.cache=false, spring.web.resources.cache.period=0}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)

2020-11-24 14:57:53.788  INFO 95795 --- [  restartedMain] com.pj.vaultdemo.VaultDemoApplication    : Starting VaultDemoApplication using Java 11.0.9 on macOsMachine with PID 95795 (/Users/jaddap2/IdeaProjects/HashiCorpVault-SpringCloud/target/classes started by jaddap2 in /Users/jaddap2/IdeaProjects/HashiCorpVault-SpringCloud)
2020-11-24 14:57:53.792  INFO 95795 --- [  restartedMain] com.pj.vaultdemo.VaultDemoApplication    : The following profiles are active: demo
2020-11-24 14:57:53.895  INFO 95795 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-11-24 14:57:53.895  INFO 95795 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-11-24 14:57:54.904  INFO 95795 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-24 14:57:54.962  INFO 95795 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 48 ms. Found 1 JPA repository interfaces.
2020-11-24 14:57:55.300  INFO 95795 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=80a5ef39-fa0c-39ac-928e-c0ba95b06c78
2020-11-24 14:57:56.347  INFO 95795 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2020-11-24 14:57:56.358  INFO 95795 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-11-24 14:57:56.359  INFO 95795 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.39]
2020-11-24 14:57:56.490  INFO 95795 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-11-24 14:57:56.491  INFO 95795 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2594 ms
2020-11-24 14:57:56.580  WARN 95795 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$JpaInvokerConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
2020-11-24 14:57:56.585  INFO 95795 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-11-24 14:57:56.627  INFO 95795 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-24 14:57:56.661 ERROR 95795 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$JpaInvokerConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:429) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1780) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$247/000000000000000000.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1161) ~[spring-context-5.3.1.jar:5.3.1]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) ~[spring-context-5.3.1.jar:5.3.1]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588) ~[spring-context-5.3.1.jar:5.3.1]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-2.4.0.jar:2.4.0]
    at com.pj.vaultdemo.VaultDemoApplication.main(VaultDemoApplication.java:11) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.0.jar:2.4.0]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$247/000000000000000000.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.cloud.autoconfigure.RefreshAutoConfiguration$JpaInvokerConfiguration.init(RefreshAutoConfiguration.java:131) ~[spring-cloud-context-3.0.0-20201123.160522-488.jar:3.0.0-SNAPSHOT]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.3.1.jar:5.3.1]
    ... 25 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$247/000000000000000000.getObject(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfUnique(DefaultListableBeanFactory.java:2050) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.getDataSourceInitializer(DataSourceInitializerInvoker.java:98) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.afterPropertiesSet(DataSourceInitializerInvoker.java:61) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784) ~[spring-beans-5.3.1.jar:5.3.1]
    ... 40 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.3.1.jar:5.3.1]
    ... 57 common frames omitted
Caused by: java.lang.IllegalArgumentException: URL must start with 'jdbc'
    at org.springframework.util.Assert.isTrue(Assert.java:121) ~[spring-core-5.3.1.jar:5.3.1]
    at org.springframework.boot.jdbc.DatabaseDriver.fromJdbcUrl(DatabaseDriver.java:283) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:229) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90) ~[spring-boot-autoconfigure-2.4.0.jar:2.4.0]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.1.jar:5.3.1]
    ... 58 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:59487', transport: 'socket'

Process finished with exit code 0


正如 Nicoll 所指出的,在 Spring Cloud Vault 3.0 和 Spring Boot 2.4 中,引导上下文初始化 (bootstrap.yml, bootstrap.properties)的财产来源为已弃用。这可以通过两种方式之一修复

  1. 使用 Spring Boot 2.4.0 Config Data API 从 Vault 导入配置(首选)
  2. 遗留处理:通过设置配置属性来启用引导上下文spring.cloud.bootstrap.enabled=true或者通过包含依赖项
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

1.使用Spring Boot 2.4.0配置数据API(首选)

Move bootstrap.yml配置为应用程序.yml更新后的文件如下所示

应用程序.yml

spring:
  cloud:
    vault:
      authentication: APPROLE
      app-role:
        role-id: ${role-id}
        secret-id: ${secret-id}
        role: pres-read
        app-role-path: approle
      uri: ${vault-server}
      connection-timeout: 5000
      read-timeout: 15000
  config:
    import: vault://secret/app/pres/

并定义单独的配置文件,如下所示。添加spring.config.import: vault://secret/app/pres/demo财产。

应用程序演示.yml

## Server Properties
server:
  port: 8081

spring:
  config:
    import: vault://secret/app/pres/demo
  datasource:
    username: ${pres.db.username}
    password: ${pres.db.password}
    url: ${pres.db.url}
    driver-class-name: com.mysql.cj.jdbc.Driver

对 dev、test、qc、staging 和 prod 等所有配置文件重复相同的过程。

2. 遗留处理:

如果还想使用,添加以下依赖bootstrap.yml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

到项目。问题将会得到解决。

See Spring Cloud Vault 文档 https://github.com/spring-cloud/spring-cloud-vault/tree/v3.0.0-M5了解更多信息

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Cloud 2020.0 不再处理 bootstrap.yml 配置 的相关文章

  • Android:对于具有 LinearLayout 定义的成员的 ListView,上下文菜单不显示?

    我有一个 ListActivity 和 ListView 并且我已将一些数据绑定到它 数据显示得很好 而且我还为视图注册了一个上下文菜单 当我将列表项显示为简单的 TextView 时 它工作正常
  • Hibernate 每个子类一个表继承策略的效率

    我正在考虑 Hibernate 管理的类层次结构的表布局 当然 每个子类表技术在我看来是一般意义上最合适的 然而 通过逻辑思考 我对其性能有些担忧 尤其是随着子类数量的扩展 举一个非常简短 且经典 的示例 假设您有以下类 public ab
  • 从另一个进程捕获 system.out 消息

    我有一个 JVM 1 它启动 JVM 2 我希望能够在 JVM 1 中监视来自 JVM 2 的 System out println 调用 直接的方法是 JVM A 执行系统命令来启动 JVM B 然后 JVM A 读取 B 的所有输出 S
  • 查找所有数组的长度多维数组,Java

    我想使用多维数组来存储数据网格 但是 我还没有找到一种简单的方法来查找长度2nd数组的一部分 例如 boolean array new boolean 3 5 System out println array length 只会输出3 是否
  • Glassfish 4 - JDBC 领域

    Glassfish 4 中的密码加密算法和摘要算法有什么区别 因为Password加密算法不能为空 所以我使用了MD5 Encoding使用了Hex 摘要算法为空 因此默认为 SHA 256 但是 如果我使用 JAAS 制作一个简单的登录应
  • 模式更新后 jOOQ 生成的类的运行时验证?

    我用org jooq util DefaultGenerator在构建过程中生成 jOOQ 类来表示我的数据库模式 当应用程序运行时 架构预计会在应用程序不知情的情况下发生更改 此类更改可能与已生成的代码兼容 也可能不兼容 如何在运行时检测
  • AMQP Spring 集成错误处理

    我的集成流程如下所示 Bean public IntegrationFlow auditFlow Qualifier eventLoggingConnectionFactory ConnectionFactory connectionFac
  • 我可以使用 Selenium Webdriver 测试元素的顺序吗?

    有一个表单 其中有 3 个字段 具有 3 个不同的 ID fieldset div div fieldset
  • ThreadPoolExecutor 和队列

    我以为使用线程池执行器 http docs oracle com javase 6 docs api java util concurrent ThreadPoolExecutor html我们可以提交Runnables 要在以下位置执行B
  • 如何在 QueryDSL 中选择文字

    我目前正在开发一个使用 queryDSL 和 hibernate 的项目 其中它需要一个选择文字 按照发布的示例here https stackoverflow com questions 18691317 querydsl how to
  • 不使用 length() 方法的字符串长度[关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 如何在不使用字符串的情况下找到字符串的长度length String类的方法 str toCharArray length应该管用 或者怎么
  • 将 Maven 控制台与 m2eclipse 一起使用

    Maven 新手在这里 有没有办法在 Eclipse 中打开控制台并在 M2Eclipse 插件上执行 Maven 命令 这是一个非常好的插件 但我环顾四周 没有找到我想要的一些功能 谢谢 如果你想运行特定的maven插件 你可以这样做 g
  • 在 Apache Servicemix 4 中的 OSGi 包之间共享配置文件?

    有人能够在 SMX4 中的两个或多个捆绑包之间成功共享配置吗 我正在寻找的是这样的 有一个文件 SMX HOME etc myconfiguration cfg 使此配置 可用 以便使用 Spring dm 通过 OSGi 配置管理将其注入
  • gwt 文本框添加更改处理程序

    我有一个从设计师那里收到的文本框 但是我在 GWT 中编写了操作 问题是文本框为空 但是当通过按下按钮用值填充文本框时 将显示警报框 通知值已更改 但没有成功 帮助我 TextBox zip1 null function onModuleL
  • Web 服务客户端的 AXIS 与 JAX-WS

    我决定用Java 实现Web 服务客户端 我已经在 Eclipse 中生成了 Axis 客户端 并使用 wsimport 生成了 JAS WS 客户端 两种解决方案都有效 现在我必须选择一种来继续 在选择其中之一之前我应该 考虑什么 JAX
  • 对于双核手机,availableProcessors() 返回 1

    我最近购买了一部 Moto Atrix 2 手机 当我尝试查看手机中的处理器规格时 Runtime getRuntime availableProcessors 返回 1 proc cpuinfo 也仅包含有关处理器 0 的信息 出于好奇
  • 如何在 Hibernate 中自动递增复合主键中的 Id?

    我有一个带有复合主键的表 groupId and batchId 实体类看起来像 Entity name EMPLOYEE public class Employee EmbeddedId private EmployeePK employ
  • 空检查时可能未初始化错误

    我正在检查变量是否已初始化 但此时 netbeans 给了我variable reader might not have been initialized警告 我该如何解决 抑制这个问题 这是我的代码 摘要 final Reader rea
  • Android Webview:无法调用确定的可见性() - 从未见过 pid 的连接

    我有一个 Android Webview 当我单击链接下载文件 pdf 图像等 时 我收到一条错误消息 Error message Cannot call determinedVisibility never saw a connectio
  • 需要在没有wsdl的情况下调用soap ws

    我是网络服务的新手 这个网络服务是由 siebel 提供的 我需要调用一项网络服务 我的客户向我提供了以下详细信息 这是 SOAP 对于产品 请使用它作为端点 Request

随机推荐

  • AngularJS 选择的空值

    我找不到优雅的设置方式null值与
  • Azure blob 文件下载链接

    我有一个 blob 已存储在 Azure blob 存储中 使用开发模拟器 它全部保存 我可以在 blob 存储的服务器资源管理器中看到它 file mp3 如果重要的话 然后我在我的网站中链接到它 但是当我单击该链接时 我收到了 206
  • 阻止 Laravel 中的路由会话(自定义按需会话处理)

    我正在使用 laravel 为我的 Android 应用程序构建 API 并将默认会话驱动程序设置为 REDIS 我在这里找到一篇好文章http dor ky laravel prevent sessions for routes via
  • 源文件夹不在Java构建类路径上,正在创建Java包

    我试图在排序下创建一个包合并 但它说 源文件夹不在 Java 构建类路径上 So I right click on sort folder and try to add it to the Java build class path But
  • MSN 是 OpenID 提供商吗?

    MSN 是 OpenID 提供商吗 如果是这样 您知道 URL 是什么样的吗 我正在尝试将 MSN 添加到具有用于登录网站的特殊按钮的提供商列表中 Microsoft 有一个附加到 Windows Live ID 的 OpenID 服务目前
  • Firebase 中 IN 关键字的替代是什么?

    我在 Firebase 中的节点为 users uid phone name 我正在寻找IN执行这里 我想检查我的数据库中存在电话号码列表中的哪些条目 然后获取这些条目 在 SQL 数据库中 等效查询可能是 select phone fro
  • 为什么Webpack的DefinePlugin要求我们将所有内容都包装在JSON.stringify中?

    new webpack DefinePlugin PRODUCTION JSON stringify true VERSION JSON stringify 5fa3b9 BROWSER SUPPORTS HTML5 true TWO 1
  • 在 Hive HQL 中将字符串转换为时间戳

    我有一个像 08 03 2018 02 00 00 这样的字符串 我试图将其转换为时间戳值 我正在使用下面的代码 unix timestamp 08 03 2018 02 00 00 yyyy MM dd T HH mm ss SSSXXX
  • 仅更改所选选项的颜色

    我有一个选择器位于表格单元格中 表格行有颜色 因此使用 CSS 我可以将下拉菜单的背景更改为相同的颜色background color inherit 但是 它会更改所有选项的整个框的颜色 是否可以仅更改所选选项的颜色 如果不使用 CSS
  • Elasticsearch 范围查询和范围过滤的区别

    我想查询某个日期范围内的elasticsearch文档 我现在有两个选择 两个都适合我 两个都测试过 1 范围查询 2 范围过滤器 由于我现在的数据集很小 因此我无法测试它们的性能 这两者有什么区别 哪一种会导致更快的文档检索和更快的响应
  • OpenCv:查找多个匹配项

    我有以下内容 但我不知道如何找到源图像中的所有匹配项 static void Main using var template Cv LoadImage images logo png LoadMode GrayScale using var
  • 如何通过Intent接收int

    我通过 Intent 传递一个 int 但我不知道如何接收它 因为我必须从 OnCreate 方法接收一个 Intent 但如果我将它放在那里 我无法将它与代码其余部分中的另一个 int 进行比较 我在这里发送意图 public class
  • NUnit 与 Debug.Assert 冲突

    我正在使用 NUnit 为我的同事编写的库编写单元测试 他的库包含大量在无效输入时触发的 Debug Asserts 当我编写单元测试并向他的库提供无效输入时 他的 Debug Assert 会弹出一个消息框 抱怨输入错误 我觉得他的库对无
  • 从线程返回值

    在 Python 中 如何让线程将元组或我选择的任何值返回给父级 我建议你实例化一个队列 队列 http docs python org library queue html highlight queue Queue Queue在启动线程
  • Android JUnit4 测试

    我想运行一些 JUnit4 测试 该代码依赖于一些Android库 Android XML解析器 但不创建任何activites等 当我尝试运行测试时 我发现找不到我需要的 Android 类 有没有办法使用 Android 代码运行 JU
  • Makefile 在目标体中设置全局变量

    我想通过一个配方设置一个全局变量 然后在另一个配方中引用该变量独立的 recipe 下面的代码是在配方内设置变量的示例代码 但如果在配方外部引用 则变量将保持初始值 ACTIVE a switch ifeq ACTIVE b ACTIVE
  • 使用 NLTK 解析 CoNLL-U 文件

    我知道有CoNLL U https universaldependencies org docs format htmlPython 中的解析器 我只是想得到确认NLTK没有解析 CoNLL U 或具有依赖语法的其他 CoNLL 格式 的本
  • Slack 的 Azure DevOps 扩展是否会受到更改 Azure DevOps URL 的影响?

    在公司 我们将 Azure Devops 工作区的 URL 从https oldname visualstudio com to https dev azure com newname 我们使用两种方法与 Azure DevOps 中的 S
  • 单核上的多线程有什么意义?

    我最近一直在研究 Linux 内核 并回顾了大学操作系统课程的时代 就像那时一样 我正在玩线程之类的东西 一直以来我一直假设线程是自动在多个核心上同时运行但我最近发现您实际上必须显式编写代码来处理多个核心 那么单核上的多线程有什么意义呢 我
  • Spring Cloud 2020.0 不再处理 bootstrap.yml 配置

    In my Spring Boot 项目 https github com pavankjadda HashiCorpVault SpringCloud 我定义了4个配置文件 demo dev test prod 在启动过程中 YAML 文