Spring Boot 2.0.0.M4 OAuth2令牌端点抛出org.springframework.web.HttpRequestMethodNotSupportedException [英] Spring Boot 2.0.0.M4 OAuth2 token endpoint throws org.springframework.web.HttpRequestMethodNotSupportedException
问题描述
我正在尝试从Spring Boot 1.5.7
迁移到2.0.0.M4
I'm trying to migrate from Spring Boot 1.5.7
to 2.0.0.M4
现在我无法在Spring Boot 2.0.0.M4上正确地重新配置OAuth2 + JWT配置
Right now I'm unable to properly reconfigure my OAuth2 + JWT configuration on Spring Boot 2.0.0.M4
在启动过程中,我在日志中发现/oauth/token
终结点(throws org.springframework.web.HttpRequestMethodNotSupportedException
)的以下错误:
During startup, I noticed following errors for /oauth/token
endpoint (throws org.springframework.web.HttpRequestMethodNotSupportedException
) in the log:
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)
In order to reproduce this issue I hve created GitHub project - https://github.com/Artgit/spring-boot-2.0.0.M4-oauth2-token-issue/tree/master/api
我要产生此问题,请尝试执行com.decisionwanted.domain.api.decision.DecisionControllerIT.testCreateDecision()
测试
I order to produce this issue please try to execute com.decisionwanted.domain.api.decision.DecisionControllerIT.testCreateDecision()
test
对于代码和pom.xml中的混乱,我深表歉意.我已经从多模块Maven应用程序中编译了这个测试项目,用于测试.
I apologize for the mess in the code and pom.xml. I have compiled this test project from the multimodule Maven application for test purpose.
请帮助我修复配置,以便能够使用Spring Boot 2.0.0.M4
Please help me fix my configs in order to be able work with Spring Boot 2.0.0.M4
已更新
在调试时,我发现application.properties
中的server.contextPath: /api
没有考虑在内.现在,我需要使用/oauth/token
(而不是像我在Spring Boot 1.5.7中使用的那样使用/api/oauth/token
)来获取令牌.这可能是什么原因以及如何解决?
While debugging, I found that server.contextPath: /api
from application.properties
is not taking into account. Right now I need to use /oauth/token
(instead of /api/oauth/token
like I use with Spring Boot 1.5.7) in order to obtain the token. What can be a reason of this and how to fix it ?
推荐答案
我发现了问题的原因-根据以下文档//带有Spring Boot 2的https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ *为了定义应用程序的上下文路径,应使用以下属性:
I found the reason of the issue - according to the following documentation https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ with Spring Boot 2* the following property should be used in order to define context path of the application:
server.servlet.context-path= /api
请注意,Spring Boot 1.5.*属性
Please note that Spring Boot 1.5.* property
server.contextPath: /api
不再被考虑
这篇关于Spring Boot 2.0.0.M4 OAuth2令牌端点抛出org.springframework.web.HttpRequestMethodNotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!