springcloud费话之配置中心server修改

时间:2019-10-31
本文章向大家介绍springcloud费话之配置中心server修改,主要包括springcloud费话之配置中心server修改使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

目录:

springcloud费话之Eureka基础

springcloud费话之Eureka集群

springcloud费话之Eureka服务访问(restTemplate)

springcloud费话之Eureka接口调用(feign)

springcloud费话之断路器(hystrix in feign)

springcloud费话之配置中心基础(SVN)

springcloud费话之配置中心客户端(SVN)

springcloud的配置中心,即config-server的端口只能之8888的问题比较恶心

原因在于spring代码中写死了每一个获取配置的客户端,都是向8888请求,因此问题出在客户端上

但是服务端也要进行一定程度的修改

思路:

修改config服务端端口,改为非8888端口

修改config客户端获取配置的方式,从固定的ip和端口,修改为通过eureka注册中心,通过注册的名称来获取

将config的服务端添加进eureka注册中心

实际代码如下:

修改config-server的配置如下:

server:
  port: 9999
  tomcat:
    max-threads: 10000
    max-connections: 20000

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:10086/eureka/

spring:
  application:
    name: config-server
  profiles:
    active: subversion
  cloud:
    config:
      server:
        svn:
          uri: https://xxxxxx/svn/liuyuhang_FM/configCenter/
          username: liuyuhang
          password: xxxxxx
          search-paths: null
          default-label: testConfig
        basedir: /data

修改config-client配置如下:

server:
  port: 8889
  tomcat:
    max-threads: 10000
    max-connections: 20000
spring:
  application:
    name: config-client
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server
      
  profiles:
    active: dev
    
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:10086/eureka/

注意spring的application的name一定要正确

注意config-client中的discovery中,要enable为true,表示可以被发现

然后指定service-id,来代替之前的uri配置即可

因为config-server中添加了eureka作为客户端,pom需要引入eureka的内容,节选如下:

     <!-- eureka server的jar, 作为client也需要 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <!-- eureka client的jar -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

添加了以后,config-server还需要对启动入口添加eureka的client的注解,节选代码如下:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableEurekaClient
@EnableConfigServer
public class ConfigApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

以上~

原文地址:https://www.cnblogs.com/liuyuhangCastle/p/11772403.html