目录:
springcloud费话之Eureka服务访问(restTemplate)
springcloud费话之Eureka接口调用(feign)
springcloud费话之断路器(hystrix in feign)
在集群运行的过程中,难以对整体的配置进行修改
所以集群的配置修改,在统一的位置中进行修改是普遍手段
在springcloud中,使用配置中心进行管理
一、配置
1.获取pom
使用svn的方式,还需要svnkit的pom
完整pom代码如下
<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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.lyh</groupId> <artifactId>lyh-config</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>lyh-config</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <!-- SR2会报错,未解决 --> <spring-cloud.version>Greenwich.SR1</spring-cloud.version> </properties> <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> <dependencies> <!-- config的server --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <!-- svn的客户端lib --> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
2.创建maven项目并引入pom
略
3.配置svn地址相关
yarm的配置,文件名为bootstrap.yml,而并非application.yml
server: port: 9000 spring: application: name: config-server profiles:#必须指定为svn,否则默认访问git active: subversion cloud: config: server: svn: uri: https://47.105.121.158/svn/liuyuhang_FM/configCenter/#svn要访问的最终文件夹地址 username: liuyuhang password: ********* search-paths: #这一项应该有,允空 default-label: testConfig
basedir: /data #临时文件夹,防清空
svn的update地址,对应关系如下:
包含文件如下:
二、创建启动类
1.创建启动类并添加注解@EnableConfigServer,代码如下:
package com.lyh.lyh_eureka_server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableConfigServer public class ConfigRun { public static void main(String[] args) { SpringApplication.run(ConfigRun.class, args); } }
三.测试
注意访问地址和svn配置相关的对应关系
访问地址,dev下地址和结果
访问具体文件的地址和结果
以上!