spring-boot - 在 Spring Cloud Bus 中 POST /actuator/bus-refresh 时出现“方法不允许”错误
问题描述
我正在使用 Spring Cloud Bus 和 RabbitMQ 向某些微服务广播配置更改,但是当我向http://localhost:8888/actuator/bus-refresh发出 POST 请求时,我收到一个错误“方法不允许”,如以下:
HTTP/1.1 405
Allow: GET
Content-Type: application/json
Transfer-Encoding: chunked
Date: Thu, 26 Mar 2020 05:53:36 GMT
Connection: close
{
"timestamp": "2020-03-26T05:53:36.872+0000",
"status": 405,
"error": "Method Not Allowed",
"message": "Request method 'POST' not supported",
"path": "/actuator/bus-refresh"
}
这是我的 application.yml 文件
server.port: 8888
spring.cloud.config.server.git.uri: E:/Work/git/microservices-poc-using-spring-cloud/config-repo
management:
endpoints:
web:
exposure:
include: bus-refresh,refresh
但是,当我更改曝光属性以允许所有端点时,我得到了成功响应,并且更改成功地广播到了我的微服务。
management:
endpoints:
web:
exposure:
include: "*"
并且响应成功。
HTTP/1.1 204
Date: Thu, 26 Mar 2020 05:42:32 GMT
Connection: close
我的 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.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.sabahallah.microservices</groupId>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-server</name>
<description>Microservices Config Server</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- for broadcasting configuration changes -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- ************************* -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</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>
而且只有一个java文件
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
解决方案
将以下内容添加到 application.properties 为我解决了这个问题。
management.endpoints.web.exposure.include=*
或者具体来说,您可以为所需的端点添加支持
management.endpoints.web.exposure.include=busrefresh
请注意,在旧版本中它是“总线刷新”
推荐阅读
- javascript - 根据经过的秒数关闭超时
- php - 通过 php (Google Places API) 从多维数组中获取值
- python - AES 密钥,解密器 = AES.new(HEADER_KEY, AES.MODE_CBC, 16 * '\x00')
- flutter - Flutter Complex Parsing Json Undefined getter "List
' - amazon-web-services - 无法将弹性 IP 重新分配给 EC2 扩展组
- fabricjs - 如何在自由绘图中重复路径?
- sql-server - “服务器”在嵌入式服务器 dbms 中的作用是什么?- 在寻找合适的 rdbms 时出现的许多与“服务器”相关的术语感到困惑
- python-3.x - 如何使用 for 循环将键和值对添加到新的空字典?
- flutter - 在没有互联网的情况下连接两部智能手机 (Flutter)
- reactjs - setState 钩子没有正确更新,即使在异步处理之后