最近做项目遇到vue生产环境打包,合并到springboot中去,遇到不少的坑
其中就有vue的跨域问题,在springcloud的配置如下:
package com.itmuch.cloud.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MyConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
};
}
}
这样就不用每个controller中配置crossorigin了
2049

被折叠的 条评论
为什么被折叠?



