title: How to integrate Spring Boot, Camel and Mybatis
body: <p>Need to Integrate Camel and MyBatis with application using SpringBoot.
  SpringBoot provides out-of-box support for Camel and MyBatis. Also provides Camel and MyBatis SpringBoot starters.</p>
  
  <p>However, when i try to integrate Spring Boot application with Camel and MyBatis, it fails.</p>
  
  <p>I am using Java DSL based Camel Route. Also using Mybatis Spring boot dependencies. Annotate mappers, added database properties in the application.properties file. What I was expecting to happen:
  1) SpringBoot setup datasource and mappers, sqlsessionfactory on start-up. 
  2) Next the Camel-MyBatis consumer is called, the setup done in (1) would allow, Camel to successfully make database calls using mybatis. </p>
  
  <p>I created spring annotated configuration class and used it to create/get DataSource bean.</p>
  
  <p>How can i get Camel to use this dataSource bean?
  How to tell Camel to use newly build SQL session factory, instead of it trying to build from configuration file?</p>
  
  <p><strong>Created sample appl in github, its using in-memory db (h2)</strong><br>
  <a href="https://github.com/RakeshBhat/rb-springcamelmybatis" rel="nofollow">sample-app</a></p>
  
  <p><strong>Getting NPE</strong> 
  Consumer[mybatis://getClaimInfo?statementType=SelectOne] failed polling endpoint: Endpoint[mybatis://getClaimInfo?statementType=SelectOne]. Will try again at next poll. Caused by: [org.apache.ibatis.exceptions.PersistenceException - </p>
  
  <h3>Error opening session.  Cause: java.lang.NullPointerException</h3>
  
  <h3>Cause: java.lang.NullPointerException]</h3>
  
  <pre><code>at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.4.0.jar:3.4.0]
  </code></pre>
  
  <p>at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100) ~[mybatis-3.4.0.jar:3.4.0]
  at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47) ~[mybatis-3.4.0.jar:3.4.0]</p>