Spring RestController端点全部重定向到' /'根路线

时间:2018-01-18 04:25:35

标签: java spring spring-mvc spring-boot

我有一个看起来像这样的休息端点:

@RequestMapping(path = "api/profile/majors", method = RequestMethod.GET)
public String getMajors() {
  //return profileDAO.getMajors();
  return "abc";
}

出于某种原因,每次我访问浏览器并访问:http://localhost:8080/api/profile/majors 似乎请求始终重定向到http://localhost:8080

当我在return "abc"处设置断点时,程序会停在那里,但发送回浏览器的响应仍然是http://localhost:8080/

知道为什么吗?

(更多背景:我确实运行了Spring Security过滤器,我确实调用了filterChain.doFilter(request, response);但是仍然会出现此问题..)

任何提示都会有所帮助!

我的安全配置如下:

http.cors()
                .and()
                .csrf()
                .disable()
                .authorizeRequests()
                .antMatchers(Endpoints.PROTECTED_API_PATTERN)
                .authenticated()
                .and()
                .addFilterBefore(
                        new JWTLoginFilter(loginRequestMatcher, authenticationManager(), successHandler),
                        UsernamePasswordAuthenticationFilter.class
                )
                .addFilterBefore(
                        new JWTAPIFilter(protectedAPIMatcher, authenticationManager(), cookieService),
                        UsernamePasswordAuthenticationFilter.class
                );

2 个答案:

答案 0 :(得分:0)

尝试在路径的开头使用斜杠。您的代码应该是

@RequestMapping(path = "/api/profile/majors", method = RequestMethod.GET)

希望有所帮助!

答案 1 :(得分:-2)

您可以尝试在方法getMajors上添加@ResponseBody。