访问/刷新执行器不工作时出现意外错误(类型=不允许方法,状态=405)错误
Getting unexpected error (type=Method Not Allowed, status=405) error while access /refresh actuator is not working
我创建了一个 @RestController class 并尝试使用来自配置服务器的 /refresh 执行器值。
/刷新执行器不工作。我收到以下错误。 Spring 引导版本为 2.0.0-Release。我无法升级 spring 引导版本。
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***
依赖性:-
<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>
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;
}
}
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
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
上述错误意味着 HTTP GET 在该特定端点上不受支持。
要从 spring 配置服务器刷新配置,您需要在 http://localhost:8888/secondservice/admin/refresh
上发出 HTTP POST 请求
以下来自Springguide
You can invoke the refresh Actuator endpoint by sending an empty HTTP POST to the client’s refresh endpoint
要发出 HTTP POST 请求,您可以使用任何 HTTP 客户端,例如 Postman or cURL。要使用 cURL,您可以 运行 在终端上执行以下命令
curl -X POST http://localhost:8888/secondservice/admin/refresh
我创建了一个 @RestController class 并尝试使用来自配置服务器的 /refresh 执行器值。 /刷新执行器不工作。我收到以下错误。 Spring 引导版本为 2.0.0-Release。我无法升级 spring 引导版本。
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***
依赖性:-
<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>
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;
}
}
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
There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported
上述错误意味着 HTTP GET 在该特定端点上不受支持。
要从 spring 配置服务器刷新配置,您需要在 http://localhost:8888/secondservice/admin/refresh
以下来自Springguide
You can invoke the refresh Actuator endpoint by sending an empty HTTP POST to the client’s refresh endpoint
要发出 HTTP POST 请求,您可以使用任何 HTTP 客户端,例如 Postman or cURL。要使用 cURL,您可以 运行 在终端上执行以下命令
curl -X POST http://localhost:8888/secondservice/admin/refresh