Spring

왜 bootstrap.properties가 spring-cloud-starter-config에 의해 무시됩니까?

기록만이살길 2022. 11. 13. 19:46
반응형

왜 bootstrap.properties가 spring-cloud-starter-config에 의해 무시됩니까?

1. 질문(문제점):

내 목표는 에 대한 구성을 가져오는 world-serviceconfig-service입니다.

아키텍처:

  1. config-service의존성 spring-cloud-config-server_localhost:8888
  2. world-service의존성 spring-webspring-cloud-starter-config.

내가 뭘 한거지:

  1. 구성 서버를 설정하고 GET 요청을 보내고 구성 서버 는 config-repo 저장소 에서 http://localhost:8888/hello-service/master가져옵니다 . (님의 소스코드가 필요 하시다면 이 저장소 에 푸시하겠습니다 .)hello-service.propertiesconfig-service

예상 결과: world-service포트 8081을 사용합니다.

내 실제 결과: world-service포트 8080을 사용합니다.

bootstrap.properties

spring.application.name=world-service
spring.cloud.config.uri=http://localhost:8888

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>2.4.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>world-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>world-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.0-M5</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-starter-config</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>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

</project>

2. 해결방안:

Spring Cloud 2020에서는 부트스트랩이 작동하는 방식을 변경했으며 새로운 스타터인 spring-cloud-starter-bootstrap.

반응형