简体   繁体   English

Spring未知属性'spring.cloud.config.server'

[英]Spring unknown property 'spring.cloud.config.server'

I am attempting to connect to a git config server in my spring project following the example below in an eclipse IDE我正在尝试按照以下 Eclipse IDE 中的示例连接到我的 spring 项目中的 git 配置服务器

https://cloud.spring.io/spring-cloud-static/Camden.SR5/ https://cloud.spring.io/spring-cloud-static/Camden.SR5/

However I am running into issues being able to resolve the properties needed as eclipse is not able to recognize the server property in my bootstrap.yml (unknown property 'spring.cloud.config.server')但是,我遇到了无法解决所需属性的问题,因为 Eclipse 无法识别 bootstrap.yml 中的服务器属性(未知属性“spring.cloud.config.server”)

spring:
  cloud:
    config:
      *server*:
        git:
          uri: .....config_server.git

I have included all the dependencies listed in the example above (spring-cloud-dependencies, spring-cloud-starter-config, spring-boot-starter-test) however I still receive the error.我已经包含了上面示例中列出的所有依赖项(spring-cloud-dependencies、spring-cloud-starter-config、spring-boot-starter-test),但是我仍然收到错误消息。

Is there limitations as to when this property can be used?何时可以使用此属性是否有限制? Or is there an additional dependency that is needed?或者是否需要额外的依赖?

First of all, is it just Eclipse doesn't see server and you can run it from command line with no errors?首先,是不是 Eclipse 看不到服务器并且您可以从命令行运行它而没有错误? In case if it's just Eclipse it could be just wrong indention or tabs.如果它只是 Eclipse,它可能只是错误的缩进或制表符。 Eclipse is not so smart sometimes. Eclipse 有时并不那么聪明。

  • Try to set it all to plain application.properties file.尝试将其全部设置为普通的 application.properties 文件。
  • Try to run it from command line尝试从命令行运行它

Also, I think you have to add credentials section for git + encrypted or not.另外,我认为您必须为 git + 加密与否添加凭据部分。

Here is valid example of YML that works fine in STS Eclipse: https://github.com/zobarov/spring-cloud/blob/master/edu-springcloud-configserver/src/main/resources/application.yml这是在 STS Eclipse 中运行良好的 YML 的有效示例: https : //github.com/zobarov/spring-cloud/blob/master/edu-springcloud-configserver/src/main/resources/application.yml

This was added to the question by the OP and has been moved here.这已被 OP 添加到问题中,并已移至此处。

Turns I just needed to add a spring-cloud-starter-config-server dependency.原来我只需要添加一个 spring-cloud-starter-config-server 依赖项。 Not sure why it did not get pulled in by by the others but that did the trick.不知道为什么它没有被其他人拉进来,但这确实成功了。

here is a small example of how we use it using the spring cloud config:这是我们如何使用 spring 云配置使用它的一个小例子:

bootstrap.yml引导程序.yml

spring:
  profiles:
    # this will tell spring to pick the correct profile file
    active: sheba

  # u must specify your application name for it to be found in the git repository!    
  application:
    name: OpscI2aClient

  # now we telling our git client where to locate our config files
  cloud:
    config:
      server:
        bootstrap: true

        git:
          # this the full uri to our repository where the config file
          # wich its name is ApplicationName-profileName.yml
          # are found
          uri: https://some.company.git.com/config/config-repo.git
          username: someGitUserName
          password: thePasswordOfTheGitUser
          # clone the whole config repository on startup
          the whole files in the repository are cloned!
          clone-on-start: true
          # this tell spring the name of the local repository directory
          # which in this case it shall create a directory called git_local
          relatively to where the application started
          basedir:
            git_local

so, assuming you have a git repo, it must contain a file OpscI2aClient-sheba.yml所以,假设你有一个 git repo,它必须包含一个文件 OpscI2aClient-sheba.yml

this file is just a simple spring boot configuration file, however, should not contain active profile entry.这个文件只是一个简单的 spring boot 配置文件,但是,不应该包含活动的配置文件条目。 that is it.这就对了。

Just to clarify: Assuming the application named OpscI2aClient have two profiles, dev and prod, your git configuration repositoty should actually contain, two files: 1. OpscI2aClient-dev.yml 2. OpscI2aClient-prod.yml澄清一下:假设名为 OpscI2aClient 的应用程序有两个配置文件,dev 和 prod,您的 git 配置存储库实际上应该包含两个文件:1. OpscI2aClient-dev.yml 2. OpscI2aClient-prod.yml

Hope this helps.希望这可以帮助。

I am just adding the POM in which you might find some hints as well我只是添加了 POM,您可能还会在其中找到一些提示

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.scm.id>opsc-scm-server</project.scm.id>
    <java.version>1.8</java.version>
    <slf4j.version>1.7.2</slf4j.version>
    <logback.version>1.1.3</logback.version>
    <spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

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

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</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-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>1.5.6</version>
    </dependency>

    <dependency>
        <groupId>org.jolokia</groupId>
        <artifactId>jolokia-core</artifactId>
    </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>

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

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