1 当用户直接输入地址的时候会被服务器要求重定向到http://localhost:8081/login 要求用户登录用才可以访问 当后端将http://localhost:8081/login返回给前端,前端会直接访问这个地址,就不经过node.js代理。没有代理就跨域了。
解决1 在login的接口上使用@CrossOrigin注释
解决2
protected void configure(HttpSecurity http) throws Exception
以上方法中加入以下代码
.csrf().disable()
// 没有认证时,在这里处理结果,不要重定向
.exceptionHandling().authenticationEntryPoint(new AuthenticationEntryPoint() {
@Override
public void commence(HttpServletRequest req, HttpServletResponse resp, AuthenticationException e) throws IOException, ServletException {
resp.setContentType("application/json;charset=utf-8");
PrintWriter out = resp.getWriter(