title: Spring Boot WebMvcConfigurer called twice, not resolving @Value second time
body: <p>I have a Spring Boot application, using annotation-based configuration.
  I'm trying to set some CORS rules up, but want the flexibility of having @Value variables to use so I can keep localhost connections out of the production server, etc.
  I found sample code; the problem is that my class is being called twice, and the second time the @Value variable does not translate into the value from my configuration file. The first time it does translate, but that is overwritten.</p>
  <p>Here's some sample code:</p>
  <pre><code>@Configuration
  @EnableWebMvc
  @EnableScheduling
  @ComponentScan(basePackages= {&quot;mysite.controller&quot;})
  public class ServletContextConfig implements WebMvcConfigurer{
  
      @Value(&quot;#{'${baselineCorsOrigins}'.split(',')}&quot;)
      private List&lt;String&gt; rawOrigins;
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping(&quot;/**&quot;)
          .allowedOrigins(getOrigin())
          .maxAge(3600)
          .exposedHeaders(&quot;Access-Control-Allow-Origin&quot;);
      }
      
      public String[] getOrigin() {
          int size = rawOrigins.size();
          String[] originArray = new String[size];
          return rawOrigins.toArray(originArray);
      }
  
  </code></pre>
  <p>The example works the <strong>first</strong> time the class is called. If I put a logging statement in there I can see the values translating. However, the second time it is called the value is ${baselineCorsOrigins}. Unfortunately that's the version that wins.</p>
  <p>I've reverted to hard-coding the allowed values, but that is far from ideal. Is there a known workaround?</p>