首页 > 解决方案 > Spring Boot Config Server 添加 Vault,无法取回 propertySources

问题描述

我对 Sprint Boot 很陌生,当我使用本机获取本地配置时,它运行良好,我开始使用 Vault 存储配置,不知道为什么无法取回 Vault Secret。

我正在使用最新的 java 版本 16。 org.springframework.boot: 2.5.4

如果有人有经验,请帮我弄清楚,我已经卡了好几天了。

应用程序.yml

spring:
  application:
    name: config-server
  profiles:
    active: native, vault
  cloud:
    config:
      server:
        - type: native
          search-locations: classpath:/config
        - type: vault
          port: 8200
          host: 127.0.0.1
          kvVersion: 2
server:
  port: 8071

encrypt:
  key: secretkey

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 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.optimagrowth</groupId>
    <artifactId>configserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Configuration Server</name>
    <description>Configuration Server</description>
    <properties>
        <java.version>16</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
        <docker.image.prefix>first-spring-project</docker.image.prefix>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <!--
                Spring Cloud BOM (Bill of Materials) definition
                All the subprojects that make up Spring Cloud are packaged under one Maven BOM and released as a whole.
                -->
                <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>
            <!-- This plugin is used to create a docker image and publish the image to docker hub-->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.13</version>
                <configuration>
                    <repository>${docker.image.prefix}/${project.artifactId}</repository>
                    <tag>${project.version}</tag>
                    <buildArgs>
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>install</phase>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

保险库 kv

邮递员 GET 方法

在此处输入图像描述

标签: javaspring-bootvault

解决方案


推荐阅读