我正在尝试按照以下示例在eclipse IDE中连接到我的spring项目中的git配置服务器
https://cloud.spring.io/spring-cloud-static/Camden.SR5/
但是我遇到了能够解决所需属性的问题,因为eclipse无法识别我的bootstrap.yml中的服务器属性(未知属性&#39; spring.cloud.config.server&#39;)< / p>
if(index < 0 || index >= set.size()) {
throw new DataException(...);
}
我已经包含了上面示例中列出的所有依赖项(spring-cloud-dependencies,spring-cloud-starter-config,spring-boot-starter-test)但是我仍然收到错误。
是否可以使用此属性?或者是否需要额外的依赖?
先谢谢。
更新:转向我只需添加spring-cloud-starter-config-server依赖项。不知道为什么它没有被其他人吸引但是这样做了。谢谢大家的帮助。
答案 0 :(得分:0)
首先,只是Eclipse没有看到服务器,你可以从命令行运行它而没有错误吗? 如果它只是Eclipse,它可能只是错误的缩进或标签。 Eclipse有时候并不那么聪明。
另外,我认为您必须为git +加密或不加密凭据部分。
以下是在STS Eclipse中正常工作的YML的有效示例: https://github.com/zobarov/spring-cloud/blob/master/edu-springcloud-configserver/src/main/resources/application.yml
答案 1 :(得分:-1)
这是我们如何使用spring cloud配置使用它的一个小例子:
<强> bootstrap.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
所以,假设你有一个git repo,它必须包含一个文件OpscI2aClient-sheba.yml
此文件只是一个简单的Spring启动配置文件,但不应包含活动的配置文件条目。 就是这样。
只是为了澄清: 假设名为OpscI2aClient的应用程序有两个配置文件,dev和prod, 你的git配置repositoty实际上应该包含两个文件: 1. OpscI2aClient-dev.yml 2. OpscI2aClient-prod.yml
希望这有帮助。
我只是添加了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>