简体   繁体   English

Spring oauth2 oauth/token http 405 错误不支持POST方法

[英]Spring oauth2 oauth/token http 405 error POST method not supported

I am facing HTTP 405 error for oauth/token on tomcat 8(linux), while other POST requests are working fine.我在 tomcat 8(linux) 上遇到 oauth/token 的 HTTP 405 错误,而其他 POST 请求工作正常。

Above issue not appears on windows localhost tomcat 8.以上问题未出现在 windows localhost tomcat 8 上。

Any clues ??有什么线索吗??

Thanks谢谢

I had the same issue, it turned out to be caused by a controller method which I used to map all endpoints to something else ie:我有同样的问题,结果证明是由我用来将所有端点映射到其他东西的控制器方法引起的,即:

@GetMapping("**")

Resolved the issue with changing the all-matching endpoint to:解决了将全匹配端点更改为:

@GetMapping("/dev/**")

My Problem got solved after adding the dependency below:添加以下依赖项后,我的问题得到了解决:

  @Bean
    public FrameworkEndpointHandlerMapping endpointHandlerMapping() {
        return new FrameworkEndpointHandlerMapping();
    }

The TokenEndpoint bean has a list of allowed HttpMethods. TokenEndpoint bean 有一个允许的 HttpMethods 列表。 The default is now just HttpMethod.POST.默认值现在只是 HttpMethod.POST。 Somehow calling the setAllowedRequestMethods after the TokenEndpoint bean has been created will fix this.在创建 TokenEndpoint bean 后以某种方式调用 setAllowedRequestMethods 将解决此问题。 I did this to fix it in a project:我这样做是为了在一个项目中修复它:

@Configuration
public class OAuth2ProviderTokenGetAllowedBackwardsCompatible implements InitializingBean
{
    @Autowired
    private TokenEndpoint tokenEndpoint;

    @Override
    public void afterPropertiesSet() {
        tokenEndpoint.setAllowedRequestMethods(new HashSet<HttpMethod>() {{
            add(HttpMethod.GET);
            add(HttpMethod.POST);
        }});
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM