欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring cloud 配置中心

程序员文章站 2022-03-04 09:36:17
...
@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class ConfigCenterApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigCenterApplication.class, args);
}
}

pom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
application.yml
logging.level.com.netflix: error

server:
  port: 10005
spring:
  application:
    name: config-service
eureka:
  instance:
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    lease-renewal-interval-in-seconds: 1
lease-expiration-duration-in-seconds: 2
---
spring:
  profiles: sit
  cloud:
    config:
      server:
        git:
           uri: http://xx.xx.xx.xx/config/vcs/config-repo.git
           search-paths: vcs-*
           force-pull: true
           username: xx
           password: xx
           basedir: ./config-repo
           timeout: 10
eureka:
  client:
    service-url:
      defaultZone: http://xx.xx.xx.xx:10001/eureka/
---
spring:
  profiles: uat
  cloud:
    config:
      server:
        git:
           uri: http://1xx.xx.xx.xx/config/vcs/config-repo.git
           search-paths: vcs-*
           force-pull: true
           username: xx
           password: xx
           basedir: ./config-repo
           timeout: 10
eureka:
  client:
    service-url:
      defaultZone: http://1xx.xx.xx.xx:10001/eureka/

Dockerfile
FROM openjdk:8-jdk-alpine
ENV LANG C.UTF-8
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo /Asia/Shanghai > /etc/timezone
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar --spring.profiles.active=$PROFILE" ]