Spring Cross Origin
in Java with 3148 comments

Spring Cross Origin

in Java with 3148 comments

Filter

   public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) 
    throws IOException,ServletException {
        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);
    }

Annotation

WebMvcConfigurer

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/api/**")
        .allowedOrigins("http://domain.com")
        .allowedMethods("PUT", "DELETE")
            .allowedHeaders("header1", "header2", "header3")
        .exposedHeaders("header1", "header2")
        .allowCredentials(false).maxAge(3600);
}

Old XML Way

Note

Responses
  1. diflucan 150 mg amoxicillin 500 mg furosemide 120 mg daily accutane otc cheap fluoxetine online

    Reply
  2. fluoxetine 10mg tablets australia diflucan 150 mg lisinopril metoprolol

    Reply
  3. 25 mg prednisone lisinopril 20mg clomid medicine doxycycline 100mg for sale diflucan prescription

    Reply
  4. Aftеr looking over a few of the blog articles ᧐n your blog, І truly like уouг way ᧐f blogging.

    І bookmarked it tο my bookmark webpage list and wіll be
    checking Ƅack in tһе near future. Тake a looқ at my
    website toⲟ and tell me how you feel.

    Reply