需要集成骆驼和MyBatis与应用程序使用SpringBoot。SpringBoot为骆驼和MyBatis提供了开箱即用的支持.还提供骆驼和MyBatis SpringBoot入门。
但是,当我尝试将Spring应用程序与Camel和MyBatis集成时,它失败了。
我正在使用基于Java的骆驼路由。还使用Mybatis启动依赖项。注释映射器,在application.properties文件中添加数据库属性。我所期待的是: 1) SpringBoot设置数据源和映射器,sqlsessionfactory在启动时。2)接下来调用Camel-MyBatis使用者,在(1)中完成的设置将允许,Camel成功地使用mybatis进行数据库调用。
我创建了spring带注释的配置类,并使用它创建/获取DataSource bean。
我怎样才能让骆驼使用这个dataSource豆?如何告诉Camel使用新构建的SQL会话工厂,而不是尝试从配置文件构建?
在github中创建了示例appl,它使用内存中的db (h2)
获取NPE Consumermybatis://getClaimInfo?statementType=SelectOne的未通过轮询端点: Endpointmybatis://getClaimInfo?statementType=SelectOne.将在下一次投票中再试一次。原因:[org.apache.ibatis.exceptions.PersistenceException -
打开会话时出错。原因: java.lang.NullPointerException
原因: java.lang.NullPointerException]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.4.0.jar:3.4.0]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) -3.4.0.jar:3.4.0
发布于 2016-07-16 03:33:14
我成功地使用了Spring 1.3.6,Apache 2.17.2和1.1.1:
maven中的键依赖项:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mybatis</artifactId>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
</dependency>要声明的键bean
@Bean(name="mybatis")
public MyBatisComponent myBatisComponent( SqlSessionFactory sqlSessionFactory )
{
MyBatisComponent result = new MyBatisComponent();
result.setSqlSessionFactory( sqlSessionFactory );
return result;
}https://stackoverflow.com/questions/38292022
复制相似问题