新建一個config Server模塊;git
引入以下依賴spring
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> </dependency>//這個很重要,配置svn必需要這個 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>${snakeyaml.version}</version> </dependency>//關於yaml文件的一些格式方面的東西
配置application.yml緩存
server: port: 8666 spring: profiles: active: subversion #這裏必定要,否則會默認爲git方式 application: name: config-server cloud: consul: host: localhost port: 8500 discovery: service-name: config-server config: server: svn: uri: svn://182.254.174.181/tzg_backend_src/trunk search-paths: "{application}" #按應用名搜索問文件夾 default-label: tzg-configs #默認目錄 username: xxx password: xxx
啓動項目,訪問:http://localhost:8666/demomirco/env;http://localhost:8666/demomirco/dev;app
特別注意!!!上傳到svn的文件必定要UTF-8模式,不然讀不出來!!!(這個原理實際上是從svn吧配置文件緩存到本地,若是svn上有改動會緩存一份新的下來)踩了大半天的坑,太不容易了svn