I use the CrossOrigin annotation in Spring. Now i want to inject a Property as value to the annotation. I dont get this to work.
Now i access my property like this:
@Value("${settings.cors_origin}")
String cors_origin;
I want to inject this property to the CrossOrigin annotation:
....
@CrossOrigin(origins = cors_origin)
@RequestMapping(value="/request", method= RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> getMethod()
{
...
I tried already something like this:
@CrossOrigin(origins = "${settings.cors_origin}")
Edit 1:
Now i try to set the CORS-Header Globally in my spring config:
<context:property-placeholder location="classpath*:*appsettings.properties"/>
<mvc:cors>
<mvc:mapping path="/api/**"
allowed-origins="${test}"
allowed-methods="GET, PUT, OPTIONS, POST"/>
</mvc:cors>
This setting is also not working! The allowed origin is not the same as the one specified in the properties file. I think it will not translate the variable to the value? When i set the IP-Address in the spring config allowed-origins manually it is working. There is something wrong with the settings...
appsettings.properties:
test=http://192.168.1.200
Edit 2:
S O L V E D
I solved it for me now after a hart time of troubleshooting :-) Now i work again with the annotation @CrossOrigin. I had to add the RequestMethod Options to the Spring RequestMapping:
@RestController
@CrossOrigin(origins = {"${settings.cors_origin}"})
@RequestMapping("/api/v1")
public class MainController {
@RequestMapping(value="/request", method = {RequestMethod.GET, RequestMethod.OPTIONS}, produces = "application/json")
public ResponseEntity<?> getMethod()
{
Thanks for your help!
${settings.cors_origin}
for example. – Cheroot