o.s.web.servlet.PageNotFound : 不支持请求方法 'POST'

o.s.web.servlet.PageNotFound : Request method 'POST' not supported

我正在部署从GitHub下载的项目,一切都完成了,服务器的主要class是:

@SpringBootApplication
@Controller
@EnableDiscoveryClient

    public class AdminUIApplication {

        public static void main(String[] args) {
            SpringApplication.run(AdminUIApplication.class, args);
        }

        @RequestMapping(value = "/fe/**")
        public String redirect() {
            return "forward:/";
        }

    }
输入了

URL:http://localhost:8451/fe/login 然后点击 LOGIN IN ,但是后台日志总是报错: o.s.web.servlet.PageNotFound : Request method 'POST'不支持。 前端信息如下图:front-end information

从RequestURL的信息来看:localhost:8451/uaa/oauth/token,其实是无法访问的,因为token服务也是运行上另一台服务器提供的本机8080端口,我试过用8080访问服务,没问题。所以,我想,这就是这个错误的原因,但我不知道如何纠正它,所以我 post 这个问题在这里请求你的帮助。抱歉,我只是提供了关于 project/code 的一般信息,因为我不确定哪段代码应该 post,如果您需要其他信息或代码,请告诉我。

谢谢

看起来 redirect 方法使用 POST 重定向到 http://localhost:8451/,并且没有可用的控制器来处理它。你有带 @RequestMapping(value = "/") 的控制器吗?

@W.Zhou 控制器应该在您的服务器代码中,即在 Spring 中,因为显然 Spring Boot 仅为 GET 请求创建默认处理程序。但是,return "forward:/"; 在您的案例中保留了 POST 方法。所以如果你想转发请求为POST,你需要为它创建一个控制器:

@RequestMapping(value = "/", method = RequestMethod.POST) public String redirect2() { return "viewName"; }

另一种可能性是您在 Angular 中有一个控制器可以处理“/”GET 请求。因此,您也可以尝试在 redirect() 方法中返回 "redirect:/" 而不是 "forward:/"