访问/刷新执行器无法工作时出现意外错误(类型=不允许的方法,状态=405)错误

use*_*r84 6 spring-boot spring-cloud

我创建了一个 @RestController 类并尝试使用来自配置服务器的 /refresh 执行器值。/刷新执行器不工作。我遇到以下错误。Spring boot版本是2.0.0-Release。我无法升级 Spring Boot 版本。

http://localhost:8888/secondservice/admin/refresh

    Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Thu Jan 23 10:16:10 EST 2020
    ***There was an unexpected error (type=Method Not Allowed, status=405).
    Request method 'GET' not supported***
Run Code Online (Sandbox Code Playgroud)

依赖性:-

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <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>

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

Foo.Class

    @RefreshScope
    @RestController
    public class Foo {


        @Value("${welcome.message}")
        private String personName;

        @RequestMapping(value ="/", produces = "application/json", method = RequestMethod.POST)
        public String greet(){
            return "hello " + "POST "+ personName;
        }

    }
Run Code Online (Sandbox Code Playgroud)

bootstrap.yml

    server:
      port: 8888 
    spring:
      application:
        name: secondservice  
      cloud:
        config:
          uri: http://localhost:8890/configserverdemo
          fail-fast: false
          enabled: true
          server:
            bootstrap: true
    management:
      context-path: /admin
      security:
        enabled: false
      endpoints:
        web:
          exposure:
            include: "*"
      endpoint:
        refresh:
          enabled: true
Run Code Online (Sandbox Code Playgroud)

Mad*_*hat 6

\n

出现意外错误(类型=不允许的方法,状态=405)。\n 不支持请求方法“GET”

\n
\n\n

上述错误意味着该特定端点不支持HTTP GET 。

\n\n

要从 spring 配置服务器刷新配置,您需要在以下位置发出HTTP POST请求http://localhost:8888/secondservice/admin/refresh

\n\n

以下来自 Spring指南

\n\n
\n

您可以通过向 client\xe2\x80\x99s 刷新端点发送空 HTTP POST 来调用刷新执行器端点

\n
\n\n

要发出 HTTP POST 请求,您可以使用任何 HTTP 客户端,例如PostmancURL。要使用 cURL,您可以在终端上运行以下命令

\n\n
curl -X POST http://localhost:8888/secondservice/admin/refresh\n
Run Code Online (Sandbox Code Playgroud)\n