Create Class
Package Le.log;
Import java.io.IOException;
Import Javax.servlet.FilterChain;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.springframework.web.filter.OncePerRequestFilter;
public class Crossfilter extends Onceperrequestfilter {
@Override
protected void dofilterinternal (HttpServletRequest request,
HttpServletResponse response, Filterchain Filterchain)
Throws Servletexception, IOException {
Response.setheader ("Access-control-allow-origin", "*");
Response.setheader ("Access-control-allow-methods", "POST, GET, OPTIONS, DELETE");
Response.setheader ("Access-control-max-age", "3600");
Response.setheader ("Access-control-allow-headers", "x-requested-with,authorization");
Response.setheader ("Access-control-allow-credentials", "true");
Filterchain.dofilter (request, response);
}
}
Configure Web. xml
<!--cross-domain requests--
<filter>
<filter-name>cors</filter-name>
<filter-class>Le.log.CrossFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--End--
Spring MVC cross-domain request