小编典典

Spring Boot 2.0.0.M4 OAuth2令牌端点抛出org.springframework.web.HttpRequestMethodNotSupportedException

spring-boot

我正在尝试从Spring Boot迁移1.5.72.0.0.M4

现在,我无法在Spring Boot 2.0.0.M4上正确地重新配置OAuth2 + JWT配置

在启动过程中,我在日志中注意到/oauth/token端点(throws org.springframework.web.HttpRequestMethodNotSupportedException)的以下错误:

2017-10-04 09:52:46.841  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/authorize],methods=[POST],params=[user_oauth_approval]}" onto public org.springframework.web.servlet.View org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.approveOrDeny(java.util.Map<java.lang.String, java.lang.String>,java.util.Map<java.lang.String, ?>,org.springframework.web.bind.support.SessionStatus,java.security.Principal)
2017-10-04 09:52:46.842  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/authorize]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.authorize(java.util.Map<java.lang.String, java.lang.Object>,java.util.Map<java.lang.String, java.lang.String>,org.springframework.web.bind.support.SessionStatus,java.security.Principal)
2017-10-04 09:52:46.843  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token],methods=[GET]}" onto public org.springframework.http.ResponseEntity<org.springframework.security.oauth2.common.OAuth2AccessToken> org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.getAccessToken(java.security.Principal,java.util.Map<java.lang.String, java.lang.String>) throws org.springframework.web.HttpRequestMethodNotSupportedException
2017-10-04 09:52:46.844  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token],methods=[POST]}" onto public org.springframework.http.ResponseEntity<org.springframework.security.oauth2.common.OAuth2AccessToken> org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(java.security.Principal,java.util.Map<java.lang.String, java.lang.String>) throws org.springframework.web.HttpRequestMethodNotSupportedException
2017-10-04 09:52:46.845  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/check_token]}" onto public java.util.Map<java.lang.String, ?> org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint.checkToken(java.lang.String)
2017-10-04 09:52:46.845  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/confirm_access]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.WhitelabelApprovalEndpoint.getAccessConfirmation(java.util.Map<java.lang.String, java.lang.Object>,javax.servlet.http.HttpServletRequest) throws java.lang.Exception
2017-10-04 09:52:46.846  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/error]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.security.oauth2.provider.endpoint.WhitelabelErrorEndpoint.handleError(javax.servlet.http.HttpServletRequest)
2017-10-04 09:52:46.848  INFO 11780 --- [           main] .s.o.p.e.FrameworkEndpointHandlerMapping : Mapped "{[/oauth/token_key],methods=[GET]}" onto public java.util.Map<java.lang.String, java.lang.String> org.springframework.security.oauth2.provider.endpoint.TokenKeyEndpoint.getKey(java.security.Principal)

为了重现此问题,我创建了GitHub项目-https: //github.com/Artgit/spring-
boot-2.0.0.M4-oauth2-token-
issue/tree/master/api

我要产生此问题,请尝试执行com.decisionwanted.domain.api.decision.DecisionControllerIT.testCreateDecision()测试

对于代码和pom.xml中的混乱,我深表歉意。我已经从多模块Maven应用程序中编译了此测试项目,以进行测试。

请帮助我修复我的配置,以便能够使用Spring Boot 2.0.0.M4

更新

在调试时,我发现server.contextPath: /apifrom
application.properties没有考虑在内。现在,我需要使用/oauth/token(而不是/api/oauth/token像我在Spring
Boot 1.5.7中使用的那样)来获取令牌。这可能是什么原因以及如何解决?


阅读 583

收藏
2020-05-30

共1个答案

小编典典

我发现了问题的原因-根据以下文档https://docs.spring.io/spring-boot/docs/current-
SNAPSHOT/reference/htmlsingle/与Spring Boot 2
*一起,应按顺序使用以下属性定义应用程序的上下文路径:

server.servlet.context-path= /api

请注意,Spring Boot 1.5。*属性

server.contextPath: /api

没有更多考虑

2020-05-30