无法使用执行器刷新来更新值配置服务器

问题描述 投票:0回答:1

当我尝试使用执行器/刷新在 git 上刷新我的配置服务器时遇到问题

这是我在配置客户端中使用的依赖项

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:4.1.1'
    implementation 'org.springframework.cloud:spring-cloud-starter-config'
    implementation 'org.springframework.cloud:spring-cloud-config-client'
    implementation 'org.springframework.cloud:spring-cloud-bus-dependencies:4.1.0'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'x
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
//  implementation 'org.springframework.cloud:spring-cloud-bus'
}

这是我的配置客户端中的应用程序属性

spring.application.name=transfer
server.port=8081
spring.config.import=optional:configserver:http://localhost:8888
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.profiles.active=prod
management.endpoints.web.exposure.include=*
endpoints.actuator.enabled=true
spring.cloud.config.enabled=true
management.endpoint.env.post.enabled=true
management.endpoint.restart.enabled=true

这是我使用云配置获取云服务器的控制器

@RestController
@RefreshScope
public class TransferController {


    @Value("${maintenance}")
    private String value;



    @GetMapping("/value")
    public String maintenanceConfig(){
        return value;
    }


}

这是我在 GIT“transfer-prod.properties”中的应用程序属性

message=transfer.prod 
maintenance=false new

当我尝试更改transfer-prod.properties 上的值维护,然后点击 localhost:8081/actuator/refresh 时,仅响应

[
    "config.client.version"
]

我所期望的是 [ “配置.客户端.版本”, “维护” ]

有人知道为什么吗?我需要帮助,谢谢

java spring-boot spring-boot-actuator spring-cloud-config spring-cloud-config-server
1个回答
0
投票

根据文档,您应该发送带有内容 application/json 和正文 {} 的发布请求:

$ curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"

如果我没记错的话,你发送了获取请求

© www.soinside.com 2019 - 2024. All rights reserved.