title: Spring Boot read values from application properties
body: <p>I'm not sure if I understand it correctly, but from what I got, is that I can use <code>@Value</code> annotations to read values from my <code>application.properties</code>.</p>
  
  <p>As I figured out this works only for <code>Beans</code>.</p>
  
  <p>I defined such a bean like this</p>
  
  <pre><code>@Service
  public class DBConfigBean {
  
  
      @Value("${spring.datasource.username}")
      private String userName;
  
      @Bean
      public String getName() {
          return this.userName;
      }
  }
  </code></pre>
  
  <p>When the application starts I'm able to retrieve the username, however - how can I access this value at runtime?</p>
  
  <p>Whenever I do </p>
  
  <p><code>
  DBConfigBean conf = new DBConfigBean()
  conf.getName();
  </code></p>
  
  <p><strong>* EDIT *</strong> </p>
  
  <p>Due to the comments I'm able to use this config DBConfigBean - but my initial problem still remains, when I want to use it in another class </p>
  
  <pre><code>@Configurable
  public SomeOtherClass {
  
     @Autowired
     private DBConfigBean dbConfig; // IS NULL
  
     public void DoStuff() {
         // read the config value from dbConfig
     }
  } 
  </code></pre>
  
  <p>How can I read the DBConfig in a some helper class which I can define as a bean</p>
  
  <p>Thanks</p>