今天在看Spring Cloud Config,配置时使用自己虚拟机上搭建的git,结果一直报错,查了好久终于解决了。
pom.xml 加上下面的配置
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</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>Edgware.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
启动类上加上 @EnableConfigServer 注解
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.yml
server:
port: 8087
eureka:
client:
service-url:
defaultZone: http://localhost:8081/eureka/
spring:
application:
name: config-server
cloud:
config:
label: master # 配置仓库的分支
server:
git:
uri: qinwei@ip:/home/qinwei/git/repositories/test.git # 配置git仓库地址
search-paths: config # 配置仓库路径
#username: 访问git仓库的用户名,(username和password必须配对使用,否则会报错,代码中写的)
#password: 访问git仓库的密码
passphrase: qinwei # 访问ssh私钥口令
ignore-local-ssh-settings: true # If true, use property based SSH config instead of file based.
private-key: |
你的ssh私钥
注意:
如果使用的是 Git SSH configuration,必须要配置 ignore-local-ssh-settings: true 和 private-key !!!
private-key 要注意 是在 | 后加上你的ssh私钥,不然也会报错(私钥在C:Users你的用户名.ssh文件下,id_rsa)
在网上看了好久都是没用的,最后在官网上才找到了原因,还是官网上靠谱啊。
http://cloud.spring.io/spring-cloud-static/Edgware.RELEASE/single/spring-cloud.html#_git_ssh_configuration_using_properties