복붙노트

[SPRING] @RefreshScope 및 / refresh가 작동하지 않습니다

SPRING

@RefreshScope 및 / refresh가 작동하지 않습니다

Config Server를 사용하여 스프링 외부 구성을 구현하려고했습니다. 응용 프로그램이 시작될 때 처음으로 제대로 작동하지만 속성 파일의 변경 사항이 반영되지 않습니다. / refresh endpoint를 사용하여 속성을 즉시 새로 고치려고했지만 작동하지 않는 것 같습니다. 이것에 대한 도움이 크게 도움이 될 것입니다.

localhost : 8080 / refresh에 POST를 시도했지만 404 오류 응답이 발생했습니다.

아래는 내 응용 프로그램 클래스의 코드입니다

   @SpringBootApplication
public class Config1Application {

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

@RestController
@RefreshScope
class MessageRestController {

    @Value("${message:Hello default}")
    private String message;

    @RequestMapping("/message")
    String getMessage() {
        return this.message;
    }
}

POM 파일은

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.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.M8</spring-cloud.version>
    </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-actuator</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

및 bootstrap.properties

spring.application.name=xxx
spring.cloud.config.uri=https://xxxxxx.com
management.security.enabled=false
endpoints.actuator.enabled=true

해결법

  1. ==============================

    1.엔드 포인트는 이제 Spring 2 이상에서 / actuator / refresh입니다

    엔드 포인트는 이제 Spring 2 이상에서 / actuator / refresh입니다

    의견에서 :

    참고 : Spring-Cloud를 처음 사용하고 web.exposure에서 모든 키워드를 사용할 수 있는지 확실하지 않은 경우 * (management.endpoints.web.exposure.include = *)로 설정하여 모두 노출되도록하십시오. 엔드 포인트 및 제한 사항을 나중에 알 수 있습니다.

  2. ==============================

    2.bootstrap.properties에 "management.endpoints.web.exposure.include = *"속성을 추가하고 2.0.0 이상의 스프링 버전에 대해 URL을 / actuator / refresh로 변경 한 후에 저에게 효과적이었습니다. 스프링 버전 1.0.5 URL의 경우 / refresh

    bootstrap.properties에 "management.endpoints.web.exposure.include = *"속성을 추가하고 2.0.0 이상의 스프링 버전에 대해 URL을 / actuator / refresh로 변경 한 후에 저에게 효과적이었습니다. 스프링 버전 1.0.5 URL의 경우 / refresh

  3. from https://stackoverflow.com/questions/49311068/refreshscope-and-refresh-not-working by cc-by-sa and MIT license