title: Spring Boot Camel - Autowiring issues in Camel components
body: <p>I am using Spring Boot 1.5.7 and Apache Camel 2.19.3, using Spring Boot AutoConfiguration provided by <em>spring-boot-starter-camel</em></p>
  
  <p>It is pretty basic Spring Boot and Camel initialized as in their <a href="http://camel.apache.org/spring-boot.html" rel="nofollow noreferrer">tutorial</a>, so we have a <em>RouteBuilder</em> component that does exactly that.</p>
  
  <pre><code>@Component
  public class CIFRoutes extends  RouteBuilder {
  
    @Override
    public void configure() throws Exception {
    // build routes
    }
  }
  </code></pre>
  
  <p>We have a <em>Configuration</em> that defines some beans we need in our application</p>
  
  <pre><code>@Configuration
  public class MyConfiguration {
  
    @Bean
    public void Map&lt;String, Object&gt; map() {
      return new HashMap&lt;&gt;()
    }
  }
  </code></pre>
  
  <p>Finally, we have a custom <em>InflightRepository</em> implementation that should be scanned by auto-configuration and added to the <em>CamelContext</em> which basically works, but for some reason, the component doesn't get initialized properly. Means, its dependencies are not initialized but the bean is instantiated and injected in my Application.</p>
  
  <pre><code>@Component
  public class MyCustomInflightRepository extends DefaultInflightRepository {
  
    @Autowired
    private Map&lt;String, Object&gt; map;
  
    @Override
    public void add(Exchange exchange) {
    super.addExchange(exchange);
     // ....
    }
  }
  </code></pre>
  
  <p>The problem now is that <em>map</em> remains <em>(null)</em>, I also tried adding a @PostConstruct initializer method but it doesn't get called.</p>
  
  <p>As far as I was able to reconstruct, it seems to be connected to premature in <em>CamelAutoConfiguration</em> where the <em>CamelContext</em> bean gets instantiated (done in private method <em>afterPropertiesSet</em>.</p>
  
  <pre><code>InflightRepository inflightRepository = getSingleBeanOfType(applicationContext, InflightRepository.class);
  if (inflightRepository != null) {
       LOG.info("Using custom InflightRepository: {}", inflightRepository);
              camelContext.setInflightRepository(inflightRepository);
  }
  </code></pre>
  
  <p>If <em>MyCustomInflightRepository</em> doesn't implement <em>InflightRepository</em>, the bean is initialized correctly, but indeed not recognized by Camel. When disabling auto-configuration, the bean's dependencies are injected.</p>
  
  <p>So, either I'm doing the impossible by Spring standards or there's something fishy with the Camel component for Spring.</p>