在我使用Spring 4.1.x版本并拥有自己的Cors Filter和Interceptor之前.我也使用Tomcat 8.0.8一切都很好.
因为我已将相同的应用程序移动到Tomcat 8.0.23,CORS停止工作.
因此,我将应用程序更新为我的POM中的以下版本的Spring依赖项:
org.springframework: 4.2.0.RC2
org.springframework.security: 4.0.1.RELEASE
org.springframework.security.oauth2: 2.0.7.RELEASE
org.springframework.ws.version: 2.2.0.RELEASE
spring.data.commons.core.version: 1.4.1.RELEASE
Run Code Online (Sandbox Code Playgroud)
现在,我还更新了我的securityConfiguration.xml,以获得安全4.0.1.RELEASE的正确模式.
应用程序运行正常,除CORS外,所有更改都很完美.
所以我按照说明操作并将以下内容添加到我的WebMvcConfigurerAdapter实现类中:
@Override
public void addCorsMappings(CorsRegistry registry) {
Properties prop = null;
try {
InputStream in = getClass().getResourceAsStream(
"/com/nando/config/cors.properties");
prop = new Properties();
prop.load(in);
in.close();
} catch (IOException e) {
prop = null;
}
if (prop != null) {
String domains = prop.getProperty("allowed.origins");
List<String> allowedOrigins = new ArrayList<String>(
Arrays.asList(domains.split(",")));
if (allowedOrigins.size() > 0) {
String[] arrayOrigins = null;
arrayOrigins = new String[allowedOrigins.size()]; …Run Code Online (Sandbox Code Playgroud)