简体   繁体   English

如果设置了spring.cloud.config.server.bootstrap=true,则需要使用复合配置

[英]If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration

Problem : how to get the data in the location https://github.com/TEK-Leads/Config-Properties.git问题:如何获取位置https://github.com/TEK-Leads/Config-Properties.git 中的数据

When I try to run this application, it does not showing any result, It only shows the default pass result ( see. MessageController).当我尝试运行这个应用程序时,它没有显示任何结果,它只显示默认的通过结果(。MessageController)。 or ConfigClient side logs showing this type of massage.或 ConfigClient 端日志显示这种类型的按摩。

Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/application/default": Connection refused;无法找到 PropertySource:对“http://localhost:8888/application/default”的 GET 请求出现 I/O 错误:连接被拒绝; nested exception is java.net.ConnectException: Connection refused嵌套异常是 java.net.ConnectException:连接被拒绝

When changing the config-Server side application.yml file to bootstrap.yml , when throwing the exception in below.当将配置服务器application.yml文件更改为bootstrap.yml时,在下面抛出异常时。

If you are using the git profile, you need to set a Git URI in your configuration.  If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.

Config Server Part配置服务器部分


Pom.xml xml文件

    <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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </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>

application.yml应用程序.yml

server:
  port: 9090

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/TEK-Leads/Config-Properties.git
          clone-on-start: true
        bootstrap: true
      enabled: true
   
  application:
    name: Config-Server

management:
  security:
    enabled: false

ConfigurationServerApp.class配置服务器应用程序类

package com.ramgovindhare.configserverapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerAppApplication {

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

Config Client Part配置客户端部分


Pom.xml xml文件

<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-web</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-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </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>

application.yml应用程序.yml

spring:
  application:
    name: client-config
    
  cloud:
    config:
      uri: http://localhost:9090
  config:
    activate:
      on-profile:
        active:prod
            
management:
  security:
    enabled:false
  

ConfigClient.class ConfigClient.class

    package com.ramgovindhare.configserverclientapp.contorller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class MessageController {
    
    @Value("${msg:Config Server is not working. Please check..}")
    private String msg;
    
    @GetMapping("/msg")
    public String getMsg() {
        return this.msg;
    }
}

As documented here ,正如此处记录的那样

If you use the bootstrap flag, the config server needs to have its name and repository URI configured in bootstrap.yml.如果使用 bootstrap 标志,则配置服务器需要在 bootstrap.yml 中配置其名称和存储库 URI。

You did not post your bootstrap files so it is unclear if you have defined them.您没有发布引导文件,因此不清楚您是否定义了它们。 If you have not, that could be the source of your problem since you have set spring.cloud.config.server.bootstrap to true.如果没有,那可能是问题的根源,因为您已将 spring.cloud.config.server.bootstrap 设置为 true。 In your bootstrap.properties file within the resources folder for your config server, you will need to have the following properties defined:在配置服务器的资源文件夹内的 bootstrap.properties 文件中,您需要定义以下属性:

config server bootstrap.properties配置服务器 bootstrap.properties

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/TEK-Leads/Config-Properties.git
          clone-on-start: true
        bootstrap: true
      enabled: true
   
  application:
    name: Config-Server

config client bootstrap.properties配置客户端 bootstrap.properties

spring:
  application:
    name: client-config
    
  cloud:
    config:
      uri: http://localhost:9090
  config:
    activate:
      on-profile:
        active:prod

It also might be worth noting that bootstrap context initialization is deprecated since Spring Boot 2.4 so using bootstrapping is no longer required for this setup.还可能值得注意的是,自 Spring Boot 2.4 起不推荐使用引导上下文初始化,因此此设置不再需要使用引导。 More information on that can be found at https://docs.spring.io/spring-cloud-config/docs/current/reference/html/ .有关更多信息,请访问https://docs.spring.io/spring-cloud-config/docs/current/reference/html/

Try to add the dependency in the pom.xml file:尝试在pom.xml文件中添加依赖:

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

暂无
暂无

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

相关问题 Spring 云配置服务器不使用本地属性文件 - 需要使用复合配置 - Spring Cloud Configuration Server not working with local properties file - getting need to use a composite configuration 您如何在引导文件中正确设置不同的 Spring 配置文件(用于 Spring Boot 以针对不同的云配置服务器)? - How do you properly set different Spring profiles in bootstrap file (for Spring Boot to target different Cloud Config Servers)? 为什么要在Spring Boot中使用@PropertySource时需要指定@Configuration? - Why do you need to specify @Configuration when you want to use @PropertySource in Spring Boot? 如何将Spring Cloud Config与Git and Vault复合环境存储库一起使用? - How to use Spring Cloud Config with a Git and Vault composite environment repository? 如何动态添加目录/文件(searchLocations)以供Spring-Cloud配置服务器观看? - How can you dynamically add directories/files (searchLocations) for Spring-Cloud config server to watch? 配置问题:spring-security-web类不可用。 您需要这些才能使用 <filter-chain-map> - Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map> 您是否必须将 DockerHub 与 Spring 云数据流一起使用才能使用 Python - Do you have to use DockerHub with Spring Cloud Data Flow to use Python Spring Cloud Config Client 未从服务器自动获取配置 - Spring Cloud Config Client is not fetching automatically configuration from server Spring Cloud本地与远程Config Server配置 - Spring Cloud local vs remote Config Server configuration 在Spring中将@Configuration和@ComponentScan一起使用的特定用例是什么? - What is a specific use case where you will use @Configuration with @ComponentScan in Spring?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM