如何使用Springboot 1.2.8制作CrossOrigin
我使用的是spring boot 1.2.8,但是class如何使用Springboot 1.2.8制作CrossOrigin,spring,spring-boot,cors,Spring,Spring Boot,Cors,我使用的是spring boot 1.2.8,但是classimport org.springframework.web.bind.annotation.CrossOrigin不存在。没有这个类,最好的方法是什么?在应用程序主类中添加以下bean配置: import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.
import org.springframework.web.bind.annotation.CrossOrigin
不存在。没有这个类,最好的方法是什么?在应用程序主类中添加以下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("/api/**").allowedOrigins("*").maxAge(3600);
}
};
}
}
顺便说一句:为什么是1.2.x?我建议你更新到1.5.x