title: spring boot @Value always null
body: <p>I am using spring boot 1.5.3 and trying to inject the properties from an application-dev.properties file into a Service bean but the value is always coming as null. The value does get loaded in my DevConfiguration class though.</p>
  
  <p>I have a application class as below in my base package</p>
  
  <pre><code>package com.me;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>I have a configuration class as follows in </p>
  
  <pre><code>package com.me.print.config;
  
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Profile;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.annotation.PropertySources;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  
  @Configuration
  @Profile("dev")
  @PropertySources({
      @PropertySource("classpath:application.properties"),
      @PropertySource("classpath:application-dev.properties")
  })
  @ComponentScan(value = {"com.me.print.client"})
  public class DevConfiguration {
  
      @Value("${app.service.url}")
      private String rootUri;
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
          return new PropertySourcesPlaceholderConfigurer();
      }
  
  }
  </code></pre>
  
  <p>My Service bean that I am trying to load the value into is below</p>
  
  <pre><code>package com.me.print.client;
  
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.web.client.RestTemplateBuilder;
  import org.springframework.stereotype.Service;
  import org.springframework.web.client.RestTemplate;
  
  import com.me.print.model.zitResponse;
  
  @Service
  public class zitPrintClient {
  
      private final RestTemplate restTemplate;
  
      @Value("${app.service.url}")
      private String rootUri;
  
      public zitPrintClient(RestTemplateBuilder restTemplateBuilder) {
          restTemplate = restTemplateBuilder
                  //.rootUri(rootUri)
                  .build();
      }
  
      public zitResponse getpooltatus(String poolId) {
          return restTemplate.getForObject("/pool/{poolId}/@status",
                    zitResponse.class, poolId);
      }
  
  }
  </code></pre>
  
  <p>In the above class the rootURI is always null. Does anyone have any suggestions as to what I am missing</p>
  
  <p>in my application-dev.properties file I have the following</p>
  
  <pre><code>app.service.url=http://localhost:8080/zitprint/v1
  </code></pre>
  
  <p>Thanks</p>
  
  <p>UPDATE:</p>
  
  <p>does anyone have any suggestions here as I tried to inject properties into my controller as follows:</p>
  
  <pre><code>@Value("${allowedVendors}") String allowedVendors
  </code></pre>
  
  <p>and if i put the above into a constructor it finds the value but does not find it otherwise:</p>
  
  <pre><code>public PController(@Value("${allowedVendors}") String allowedVendors) {
  
  }
  </code></pre>
  
  <p>I cant use the property further in the code as with the constructor I have created two instances of the bean 1 via the constructor and the other created by spring DI. Any ideas why the value doesnt inject without the constructor</p>
  
  <p>Thanks</p>