[Solved] interceptor Cross-Domain Access-Control-Allow-Origin Error

I use vue3 + spring boot, which is developed by front-end and back-end separation technology. For cross-domain problems, I add the following code:

public class CorsConfig implements WebMvcConfigurer {

    public void addCorsMappings(CorsRegistry registry) {
                .maxAge(3600); // No further pre-testing required within 1 hour (send OPTIONS request)


The above code is useless, and then it is used in the interceptor to add the following code:

String origin = request.getHeader("Origin");
response.setHeader("Access-Control-Allow-Origin", origin);

Add to solve the problem.

Similar Posts: