Config

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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>3.3.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.mi</groupId>
    <artifactId>config</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config</name>
    <description>config</description>
    
    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2023.0.2</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </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>

</project>

application.properties

github 仓库

spring.application.name=config


server.port=8888
eureka.instance.hostname=localhost

eureka.client.service-url.default=http://localhost:8761/eureka/


spring.profiles.active=dev

spring.cloud.config.server.git.uri=https://github.com/xxxx/config-repo.git
spring.cloud.config.server.git.username=xxx
spring.cloud.config.server.git.password=xxxx
spring.cloud.config.server.git.default-label=develop
spring.cloud.config.server.git.search-paths=config
spring.cloud.config.label=develop
server:
  port: 8082

eureka:
  instance:
    hostname: localhost
  client:
    service-url:
      default: http://localhost:8761/eureka/

spring:
  application:
    name: product
  profiles:
    active: dev
  cloud:
    config:
      name: ${spring.application.name}
      uri: http://localhost:8888
      label: develop
      profile: dev
      discovery:
        enable: true
        service-id: config

本地仓库

spring.application.name=config


server.port=8888
eureka.instance.hostname=localhost

eureka.client.service-url.default=http://localhost:8761/eureka/

spring.profiles.active=native
spring.cloud.config.server.native.search-locations=J:/java/project/config-repo/config
server:
  port: 8082

eureka:
  instance:
    hostname: localhost
  client:
    service-url:
      default: http://localhost:8761/eureka/

spring:
  application:
    name: product
  profiles:
    active: dev
  cloud:
    config:
      name: ${spring.application.name}
      uri: http://localhost:8888
      label: develop
      profile: dev
      discovery:
        enable: true
        service-id: config

DB

spring.application.name=config


server.port=8888
eureka.instance.hostname=localhost

eureka.client.service-url.default=http://localhost:8761/eureka/

# 固定值
spring.profiles.active=jdbc


spring.datasource.url=jdbc:mysql://192.168.1.11:3306/mi
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver


spring.cloud.config.server.jdbc.sql=SELECT `KEY`, `VALUE` from properties where APPLICATION=? and PROFILE=? and LABEL=?
server:
  port: 8082

eureka:
  instance:
    hostname: localhost
  client:
    service-url:
      default: http://localhost:8761/eureka/

spring:
  application:
    name: product
  profiles:
    active: dev
  cloud:
    config:
      name: ${spring.application.name}
      uri: http://localhost:8888
      label: develop
      profile: dev
      discovery:
        enable: true
        service-id: config

ConfigApplication

package com.mi.config;

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
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {

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

}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值