繁体   English   中英

应用程序不读取配置服务器 spring 云

[英]application dosen't read config server spring cloud

我尝试用 2 个应用程序创建一个简单的项目(一个简单的休息应用程序和一个配置服务器应用程序)我的配置服务器项目没问题,因为如果我得到 http://localhost:9091/form-create/container 我可以看到form-create.properties 中的所有变量

但我的应用程序表单创建没有从配置服务器获取属性

这是我在 form-create 项目中的 bootstrap.properties

spring.application.name=form-create
spring.cloud.config.uri=http://localhost:9091
spring.cloud.config.fail-fast=true

表单创建项目中的 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.2</version>
        <relativePath />
    </parent>

    <groupId>com.formcloud</groupId>
    <artifactId>ms-form-create</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>ms-form-create</name>
    <description>Microservice to manage form creation</description>
    
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </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>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <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>
        </plugins>
    </build>

</project>

主班

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

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

}

我究竟做错了什么? 如果我启动我的表单创建应用程序是在 8080 端口上启动并且没有从配置服务器获取属性。

我认为您应该尝试检查两件事:

  1. 您的 Maven 依赖项。 看起来你把它们弄错了,也就是说,如果你正在运行云配置客户端,为什么你对spring-cloud-config-server有依赖?

对于 Web 和云配置客户端,以下列表就足够了:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  1. 当您启动配置服务器时,您确定它确实从您配置的存储库(git、文件系统等)中读取了配置? 通常,它公开 REST API,因此即使不启动 spring boot 应用程序,您也可以curl服务器以获取信息

尝试并确保它按预期工作。 例如,阅读教程的这一部分 请注意,您可能已经为不同的配置文件或不同的分支放置了配置,云配置服务器可以处理它,但是您必须例如在bootstrap.properties指定配置文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM