add multiple cross origin urls in spring boot

前端 未结 6 1225
太阳男子
太阳男子 2021-02-02 13:50

I found an example on how to set cors headers in spring-boot application. Since we have many origins, I need to add them. Is the following valid?

@Configuration
         


        
6条回答
  •  感情败类
    2021-02-02 14:10

    Create your custom annotation and annotate the API with that.

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD})
    @CrossOrigin
    public @interface CrossOriginsList {
    
        public String[] crossOrigins() default  {
    
                "http://domain1.com", "http://domain1.com"
                "http://domain1.com", "http://domain1.com"
                // Pass as many as you want
        };
    }
    

    And now Annotate your API with this custom Annotation

    @CrossOriginsList
        public String methodName() throws Exception
    {
            //Business Logic
    }
    

    Worked perfectly fine for me.!!

提交回复
热议问题