add multiple cross origin urls in spring boot

前端 未结 6 1316
太阳男子
太阳男子 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:18

    In Spring boot there is an annotation @CrossOrigin which will simply add header in the response.

    1. For multiple:
    @CrossOrigin(origins = {"http://localhost:7777", "http://someserver:8080"})
    @RequestMapping(value = "/abc", method = RequestMethod.GET)
    @ResponseBody
    public Object doSomething(){
      ...
    }
    
    2. If you wanna allow for everyone then simply use.
    @CrossOrigin
    

提交回复
热议问题