1

Currently have the following configuration and the application works as expected:

@CrossOrigin(origins = { "https://localhost:5000","http://localhost:5000"})

would like to change to something that can be configured in a properties file for different environments. I Can get to work with one Value but can't figure out a way for it to work with more than one. When a properties file is application-dev.properites has:

cors.client.urls=http://localhost:5000,https://localhost:5000

The appropriates values are not loaded with the following declaration:

@CrossOrigin(origins = {"${cors.client.urls}"})

When the properties file is just one value this declaration works as expected.

I know that I am missing something extremely basic.. Appreciate any help.

Zach H
  • 11
  • 2

1 Answers1

0

You can use SpringEL here as mentioned in Reading a List from properties file and load with spring annotation @Value

@CrossOrigin(origins = {#{'${cors.client.urls}'.split(',')}}) 
AbhiW
  • 80
  • 1
  • 8
  • 1
    @CrossOrgin is defined at the class level. Maybe I am using an older version or some other lib is wrong but this does not compile.. – Zach H Oct 15 '20 at 18:04
  • This does not work at least in Java 11, I have a similar problem and when I'm trying to use this as `@CrossOrigin(origins = {"#{'${cors.client.urls}'.split(',')}"})` throws an exception `java.lang.IllegalStateException: The [property] must resolve to a String. Resolved to [class [Ljava.lang.String;] ` – Damonio Apr 05 '22 at 02:01