SpringMVC4.2 began to add a cross solution, which is explained here by adding an annotation @CrossOrigin in the controller
Check the source code of @CrossOrigin to understand that this annotation integrates the relevant configuration of cross-domain configuration by default, just add some parameters to this annotation
package org. springframework. web. bind. annotation;
import java. lang. annotation. Documented;
import java. lang. annotation. ElementType;
import java. lang. annotation. Retention;
import java. lang. annotation. RetentionPolicy;
import java. lang. annotation. Target;
import org. springframework. core. annotation. AliasFor;
@Target ( { ElementType. METHOD, ElementType. TYPE} )
@Retention ( RetentionPolicy. RUNTIME)
@Documented
public @interface CrossOrigin {
@Deprecated
String[ ] DEFAULT_ORIGINS = new String [ ] { "*" } ;
@Deprecated
String[ ] DEFAULT_ALLOWED_HEADERS = new String [ ] { "*" } ;
@Deprecated
boolean DEFAULT_ALLOW_CREDENTIALS = false ;
@Deprecated
long DEFAULT_MAX_AGE = 1800 L;
@AliasFor ( "origins" )
String[ ] value ( ) default { } ;
@AliasFor ( "value" )
String[ ] origins ( ) default { } ;
String[ ] allowedHeaders ( ) default { } ;
String[ ] exposedHeaders ( ) default { } ;
RequestMethod[ ] methods ( ) default { } ;
String allowCredentials ( ) default "" ;
long maxAge ( ) default - 1 L;
}
If the default configuration is used, it can be seen that all domain names, request headers, request methods, cookies,
If you need to specify the cross-domain domain name or other parameters can be added in the comment, for example. Other parameters can also be added
@CrossOrigin ( value = "http://www.twgfs.online" , maxAge = 30 , methods= RequestMethod. GET)