title: Spring Boot Autowired null
body: <p>I have several classes in a Spring Boot project, some work with @Autowired, some do not. Here my code follows:</p>
  
  <p>Application.java (@Autowired works):</p>
  
  <pre><code>package com.example.myproject;
  
  @ComponentScan(basePackages = {"com.example.myproject"})
  @Configuration
  @EnableAutoConfiguration
  @EnableJpaRepositories(basePackages = "com.example.myproject.repository")
  @PropertySource({"classpath:db.properties", "classpath:soap.properties"})
  public class Application {
  
  @Autowired
  private Environment environment;
  
  public static void main(String[] args) {
      SpringApplication.run(Application.class);
  }
  
  @Bean
  public SOAPConfiguration soapConfiguration() {
      SOAPConfiguration SOAPConfiguration = new SOAPConfiguration();
      SOAPConfiguration.setUsername(environment.getProperty("SOAP.username"));
      SOAPConfiguration.setPassword(environment.getProperty("SOAP.password"));
      SOAPConfiguration.setUrl(environment.getProperty("SOAP.root"));
      return SOAPConfiguration;
  }
  </code></pre>
  
  <p>HomeController (@Autowired works):</p>
  
  <pre><code>package com.example.myproject.controller;
  
  @Controller
  class HomeController {
  
      @Resource
      MyRepository myRepository;
  </code></pre>
  
  <p>MyService (@Autowired does not work):</p>
  
  <pre><code>package com.example.myproject.service;
  
  @Service
  public class MyServiceImpl implements MyService {
  
      @Autowired
      public SOAPConfiguration soapConfiguration; // is null
  
      private void init() {
      log = LogFactory.getLog(MyServiceImpl.class);
      log.info("starting init, soapConfiguration: " + soapConfiguration);
      url = soapConfiguration.getUrl(); // booom -&gt; NullPointerException
  </code></pre>
  
  <p>I do not get the SOAPConfiguration but my application breaks with a null pointer exception when I try to access it.</p>
  
  <p>I have already read many Threads here and googled around, but did not find a solution yet. I tried to deliver all necessary information, please let me know if anything misses.</p>