【问题标题】:Getting "Method Not Allowed" error when POST /actuator/bus-refresh in Spring Cloud Bus在 Spring Cloud Bus 中 POST /actuator/bus-refresh 时出现“方法不允许”错误
【发布时间】:2020-07-06 18:14:42
【问题描述】:

我正在使用 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);
    }

}

【问题讨论】:

  • /bus-refresh 不支持发布。 /monitor 接受帖子并尝试根据来自 vcs webhooks 的标题或内容来确定要刷新的服务。

标签: spring-boot microservices spring-cloud spring-boot-actuator spring-cloud-bus


【解决方案1】:

将以下内容添加到 application.properties 为我解决了这个问题。

management.endpoints.web.exposure.include=*

或者具体来说,您可以为所需的端点添加支持

management.endpoints.web.exposure.include=busrefresh

请注意,在旧版本中它是“总线刷新”

【讨论】:

    【解决方案2】:

    您好,我遇到了同样的错误并通过更改 Spring Cloud 版本解决了它。 最初我使用 Greenwich.RELEASE

    现在我已将版本更改为 Greenwich.SR1, Greenwich.SR1

    【讨论】:

      猜你喜欢
      • 2021-04-15
      • 2017-05-18
      • 2020-12-15
      • 2017-10-12
      • 1970-01-01
      • 2016-09-29
      • 2017-10-28
      • 2021-04-20
      • 2018-05-11
      相关资源
      最近更新 更多