• spring cloud 之config配置


    Spring Cloud Config服务器

    服务器为外部配置(名称值对或等效的YAML内容)提供了基于资源的HTTP。服务器可以使用@EnableConfigServer注释轻松嵌入到Spring Boot应用程序中。所以这个应用程序是一个配置服务器:

    ConfigServer.java
    @SpringBootApplication
    @EnableConfigServer
    public class ConfigServer {
      public static void main(String[] args) {
        SpringApplication.run(ConfigServer.class, args);
      }
    }

    首先搭建springboot项目  

    在resources下面创建2个.yml配置文件

    1.

    server:
    port: 8888
    spring:
    cloud:
    config:
    server:
    encrypt:
    enabled: false
    git:
    uri:  这里填写git地址
    searchPaths:  gir的目录地址   如项目是8080:admin   就填写admin多个用,号
    username: git的username
    password: gir的pass

    在git地址上创建***.yml文件 的配置  比如mysql的 redis的配置 和searchPaths地址对应

    server:
    port: 13880
    servlet:
    context-path: /admin
    spring:
    application:
    name: admin
    profiles:
    active: default
    datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql:mysql连接地址
    password: 账号
    jpa:
    hibernate:
    ddl-auto: update
    show-sql: true
    database: mysql
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    redis:
    host: 192.168.0.77
    swagger:
    enabled: true
    eureka:
    instance:
    prefer-ip-address: true
    client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
    defaultZone: eureka地址 用于发布和注册服务的  
    security:
    oauth2:
    resource:
    user-info-uri: 用于安全框架地址

    2.

    spring:
    application:
    name: configserver
    encrypt:
    key: mykey
    #debug: true

    pom.xml: 配置sprongboot和springCloud相关jar包

    <name>confsvr</name>
    <description>Demo project for Spring Boot</description>

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.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>Finchley.SR1</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</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    </dependency>
    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
    </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>

  • 相关阅读:
    用php获取本周,上周,本月,上月,本季度日期的代码
    PHP取整,四舍五入取整、向上取整、向下取整、小数截取
    图解phpstorm常用快捷键
    web安全之如何防止CSRF跨站请求伪造
    Ajax同步异步的区别
    php中文件上传需要注意的几点
    D4 HL 数据结构
    D3 HL 模拟赛订正
    D2 HL 图的高级应用 网络流专题
    D1 HL 图的高级应用 tarjan算法
  • 原文地址:https://www.cnblogs.com/laixin09/p/9593480.html
Copyright © 2020-2023  润新知