zoukankan      html  css  js  c++  java
  • springcloud20---Config加入eureka

    Config server也可以加用户名和密码。Config client通过用户名和密码访问。

    Config server也可以做成高可用集群。

    Configeureka配置使用。把Config server注册到eurekaConfig client也要注册到eureka

    package com.itmuch.cloud;
    
    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;
    
    @SpringBootApplication
    @EnableConfigServer
    @EnableDiscoveryClient
    public class ServerApplication {
      public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);
      }
    }
    server:
      port: 8080
    spring:
      cloud:
        config:
          server:
            git:
              uri: https://git.oschina.net/it-much/config-repo-51cto-video
              username: 
              password: 
      application:
        name: microservice-config-server-eureka
    
    eureka:  #config-server注册到eureka
      client:
        serviceUrl:
          defaultZone: http://user:password123@localhost:8761/eureka
      instance:
        prefer-ip-address: true
    <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>com.itmuch.cloud</groupId>
            <artifactId>microservice-spring-cloud</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    
        <artifactId>microservice-config-server-eureka</artifactId>
        <packaging>jar</packaging>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        
        <dependencies>
            <!-- config-server的依赖,config-server注册到rureka -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-server</artifactId>
            </dependency>
            <!-- eureka-client的依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
            </dependency>
        </dependencies>
        <build>
        
            <defaultGoal>compile</defaultGoal>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12.3</version>
                    <configuration>
                        <groups>unit</groups>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                      <verbose>true</verbose>
                      <fork>true</fork>
                      <compilerVersion>1.5</compilerVersion>
                    </configuration>
                </plugin>
                 
            </plugins>
        </build>
    </project>

    package com.itmuch.cloud;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class ConfigClientController {
    
      @Value("${profile}")
      private String profile;
    
      @GetMapping("/profile")
      public String getProfile() {
        return this.profile;
      }
    }
    package com.itmuch.cloud;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    
    @SpringBootApplication
    @EnableDiscoveryClient
    public class ConfigServerApplication {
      public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
      }
    }

    application.yml

    server:
      port: 8081

    bootstrap.yml

    spring:
      cloud:
        config:
          discovery:
            enabled: true
            service-id: microservice-config-server-eureka  #config server在eureka的名字
      application:
        name: foobar
        
    eureka:  #把config client注册到eureka
      client:
        serviceUrl:
          defaultZone: http://user:password123@localhost:8761/eureka
      instance:
        prefer-ip-address: true
        
    <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>com.itmuch.cloud</groupId>
            <artifactId>microservice-spring-cloud</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    
        <artifactId>microservice-config-client-eureka</artifactId>
        <packaging>jar</packaging>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</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-actuator</artifactId>
            </dependency>
        </dependencies>
    
    </project>

    配置属性加解密:

    配置在git仓库里面是明文,

    下载jce8 :

    http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

    下载之后解压:

    里面是2个加解密的策略文件。用这2个策略文件替换jdk里面的策略文件就可以了。

  • 相关阅读:
    szoj657 【AHSDFZNOI 7.2 WuHongxun】Odd
    cogs2652 秘术「天文密葬法」
    bzoj1026 [SCOI2009]windy数
    bzoj1862/1056: [Zjoi2006]GameZ游戏排名系统
    java-PreparedStatement的用法
    java-JDBC登录注册代码
    java-String Date Calendar之间的转换
    java-如何用eclipse打包jar
    java-通过JDBC操作数据库
    java-JDBC配置驱动程序
  • 原文地址:https://www.cnblogs.com/yaowen/p/9184295.html
Copyright © 2011-2022 走看看