二、配置中心
使用了SVN作为存储搭建配置中心,svn搭建请移步Docker+SVN
一、构建项目
我是使用eclispe+sts构建的 SpringBoot/SpringStarterProject
Springboot版本:1.5.8.RELEASE
SpringCloud版本:Edgware.SR3
因为使用的时Sts,所以构建时候可以勾选方式,选择EurekaServer+ConfigServer
展示一下pom.xml,看pom里面注释,需要添加SVN依赖
<?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>cnex.cloud</groupId> <artifactId>config</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>cloud-config</name> <description>config</description> <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>Edgware.SR3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!-- 添加svn依赖,一定要加 --> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.8.10</version> </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>
二、SVN目录结构
三、配置文件
server: port: 8999 spring: cloud: config: server: svn: #svn地址 uri: svn://10.180.206.134:3690/CnexCloud/ username: wjiang password: admin123. #默认节点 default-label: trunk profiles: active: subversion application: name: cloud-config #注册到注册中心 eureka: client: serviceUrl: defaultZone: http://10.180.206.254:9000/eureka/ instance: ip-address: 10.180.206.254 prefer-ip-address: true instance-id: ${eureka.instance.ip-address}:${server.port}
四、测试
这是svn下文件内容:
访问页面: ip:port/文件名
五、客户端
移步客户端