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:
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders(CorsConfiguration.ALL)
.allowedMethods(CorsConfiguration.ALL)
.allowCredentials(true)
.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:
- Gateway Error: allowedOrigins cannot contain the special value “*”
- How to Solve Error: Preflight response is not successful
- Error during WebSocket handshake 403 [How to Solve]
- JQuery Ajax crossdomain cannot be used in IE [How to Solve]
- [Solved] HttpClient HttpRequestHeaders.From Error: The specified value is not a valid ‘From’ header string.
- Spring Cloud Openfeign Get Request 405 Error [How to Solve]
- Postman Error: Could not get any response [How to Solve]
- Server returned HTTP response code: 500 for URL xxxxxxxxxxxxx
- [Solved] Cannot call sendRedirect() after the response has been committed
- [Solved] Swagger Error: Failed to start bean ‘documentationPluginsBootstrapper’