Junit 测试弹簧启动执行器自定义端点
我试图在springboot中测试一个定制的执行器端点 终点是:Junit 测试弹簧启动执行器自定义端点,junit,endpoint,spring-boot-actuator,mockmvc,Junit,Endpoint,Spring Boot Actuator,Mockmvc,我试图在springboot中测试一个定制的执行器端点 终点是: @Component @RestControllerEndpoint(id = "test") public class TestController { @PostMapping("/1") public ResponseEntity<?> testEndpoint(Request request) { } } post(“/test/1”)和post(“/1”)都得到404错误此模拟MVC测试适
@Component
@RestControllerEndpoint(id = "test")
public class TestController {
@PostMapping("/1")
public ResponseEntity<?> testEndpoint(Request request) {
}
}
post(“/test/1”)和post(“/1”)都得到404错误此模拟MVC测试适用于普通控制器
java.lang.AssertionError: Status expected:<200> but was:<404>
Expected :200
Actual :404
提前感谢。自定义端点作为子链接添加到
执行器
端点下。因此,自定义端点的url应该是/exactor/test/1
。在这种情况下,它应该是/api/v1/mycontext/test/1
,因为您已经设置了管理.endpoints.web.base路径
您可能需要在测试应用程序配置中启用执行器端点您可以提供您的整个测试类吗?我觉得您应该调用/test/1
,而不是/1
也许吧?它们都不管用,事实上,我已经两种都试过了
java.lang.AssertionError: Status expected:<200> but was:<404>
Expected :200
Actual :404
management:
server.port: 8081
endpoints:
web:
base-path: /api/v1/mycontext