I am using Spring Boot v1.5.1, and it seems my restriction on CORS origin is not working.
My application.properties file has the following line (ref1 ref2).
endpoints.cors.allowed-origins=http://mydomain.io
My REST controller looks like the following.
@RestController
@CrossOrigin
@RequestMapping("/api/car")
public class CarCtrl {
@Autowired
private CarService carService;
@GetMapping
public Car get() {
return carService.getLatest();
}
}
However, when I open up a browser and type in http://localhost:8080/api/car
I am still able to access the REST endpoint.
I also tried to change my annotation as follows, but that does not work.
@CrossOrigin("${endpoints.cors.allowed-origins}")
Any ideas on what I'm doing wrong?
Note that I am not using WebMvcConfigurerAdapter
like this post. Do I really need to extends this class to explicitly control origin? I figured that the @CrossOrigin
annotation in addition to the properties file setting would be able to control the allowed origins (as opposed to having to do so programmatically).
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…