我是使用Spring Cloud Config的新手。
我有此配置:
application.yml
server:
port: ${PORT:8888}
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/username/SpringCloudConfig
username: username
password: password
timeout: 4
security:
basic:
enabled: false
management:
security:
enabled: false
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>config-server</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.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.SR1</spring-cloud.version>
</properties>
<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>
</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>
课程
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
在以下位置启动服务器时:http://localhost:8888/health
{“状态”:“ DOWN”,“ diskSpace”:{“状态”:“ UP”,“总计”:494099492864,“免费”:440483053568,“阈值”:10485760},“ refreshScope”:{“ status”:“ UP”},“ configServer”:{“ status”:“ DOWN”,“ repository”:{“ application”:“ app”,“ profiles”:“ default”},“ error”:“ java”。 lang.IllegalStateException: 无法克隆或签出存储库“}}
我尝试启动显示的服务:
2018-08-08 13:43:38.270 INFO 32492 --- [主] c.c.c.ConfigServicePropertySourceLocator:从服务器获取配置 于:http://localhost:8888 2018-08-08 13:43:42.884 WARN 32492 --- [
main] c.c.c.ConfigServicePropertySourceLocator:无法找到 PropertySource: {“时间戳记”:1533728622334,“状态”:500,“错误”:“内部服务器 错误”,“异常”:“ java.lang.IllegalStateException”,“消息”:“无法 克隆或签出存储库“路径”:“ / producer-service / default”}”
bootstrap.yml
spring:
application:
name: producer-service
课程
@SpringBootApplication
public class ProducerServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ProducerServiceApplication.class, args);
}
}
@RestController
class Producer {
@Value("${message}")
private String message;
@Value("${global-message}")
private String globalMessage;
@RequestMapping(method = RequestMethod.GET)
public Map<String, String> message() {
Map<String, String> response = new HashMap<>();
response.put("message", message);
response.put("global-message", globalMessage);
return response;
}
}