【问题标题】:Spring Cloud Config Server IssueSpring Cloud 配置服务器问题
【发布时间】:2016-09-12 18:43:50
【问题描述】:

我目前正在尝试使用 Spring Cloud Config,但无法让 Spring Cloud Config Server 从我的 github 存储库加载属性。我一直在关注这里的文档:

http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server

这是我的 Maven pom.xml 文件:

<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.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>1.0.2.RELEASE</version>
  </parent>

  <groupId>com.example.spring.cloud</groupId>
  <artifactId>spring-cloud-test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Spring Cloud Test</name>

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

这是我的应用程序类:

package com.wth.service.config;

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

@SpringBootApplication
@EnableConfigServer
public class Application {

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

这是我的 application.yml 文件:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/crn717/TestRepo.git

server:
  port: 8001

这是我的 hello-world-default.yml 文件,位于我上面的 git 存储库中:

firstName:John
lastName:Smith

当我运行应用程序时,它可以正常启动。但是,当我访问http://localhost:8001/hello-world/default 时,我得到以下响应:

{"name":"hello-world","profiles":["default"],"label":"master","propertySources":[]}

如您所见,没有属性来源。

到目前为止,有人注意到我所做的事情有什么问题吗?我已经为此挣扎了几天,似乎无法弄清楚发生了什么。任何帮助都将不胜感激。

谢谢, 克里斯

【问题讨论】:

  • 不要在应用程序名称中使用-。因为它用于确定配置文件。

标签: spring spring-boot


【解决方案1】:

经过反复试验,我能够通过在我的 Maven pom.xml 文件中将“Angel.SR6”指定为“spring-cloud-starter-parent”工件的版本来让事情正常工作。

克里斯

【讨论】:

    【解决方案2】:

    我已尝试您的代码并得到以下响应:

     {"name":"hello-world","profiles":["default"],"label":null,"version":"68a2c21e35754e0db0dc870dc8126d8e0e8429a0","state":null,"propertySources":[{"name":"https://github.com/crn717/TestRepo.git/hello-world.properties","source":{"firstName":"John"}}]}
    

    我spring-boot-starter-parent的版本是1.5.8.RELEASE,pom.xml:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.SR4</spring-cloud.version>
    </properties>
    
    <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>
    
    <dependencies>
        <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>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    

    也许您可以将您的版本从 1.0.2.RELEAS 更新为 1.5.8.RELEASE

    【讨论】:

      猜你喜欢
      • 2017-09-07
      • 2021-05-08
      • 1970-01-01
      • 2017-07-25
      • 2023-03-24
      • 1970-01-01
      • 2018-08-24
      • 2020-09-27
      • 2021-03-21
      相关资源
      最近更新 更多