Springboot cross-domain Filter

page visit with the following 401 error

background breakpoint, the Filter class cannot be entered, and the code is not executed

here is my Filter class and inject

with @ Component annotation

ask for answers

@Component
public class CORSFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        System.out.println("Filtering on...........................................................");
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Authorization, Origin, Accept, Access-Control-Request-Method, Access-Control-Request-Headers");

        chain.doFilter(req, res);
    }

    public void init(FilterConfig filterConfig) {}

    public void destroy() {}

}

Mar.15,2022

    @Bean
    public FilterRegistrationBean httpContextFilter() {
        System.out.println("===== filter =====");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new AbcFilter());
        registration.addUrlPatterns("/*");
        registration.setName("abc");
        registration.setOrder(1);
        return registration;
    }

Lei Feng


clipboard.png
CrossOrigin Notes to understand, solve cross-domain problems, do not need to do so troublesome

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ba42-2c2da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ba42-2c2da.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?