首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Spring Boot、Camel和Mybatis集成起来

如何将Spring Boot、Camel和Mybatis集成起来
EN

Stack Overflow用户
提问于 2016-07-10 12:45:23
回答 1查看 1.6K关注 0票数 1

需要集成骆驼和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)

样本-app

获取NPE Consumermybatis://getClaimInfo?statementType=SelectOne的未通过轮询端点: Endpointmybatis://getClaimInfo?statementType=SelectOne.将在下一次投票中再试一次。原因:[org.apache.ibatis.exceptions.PersistenceException -

打开会话时出错。原因: java.lang.NullPointerException

原因: java.lang.NullPointerException]

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-16 03:33:14

我成功地使用了Spring 1.3.6,Apache 2.17.2和1.1.1:

maven中的键依赖项:

代码语言:javascript
复制
<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

代码语言:javascript
复制
@Bean(name="mybatis")
public MyBatisComponent myBatisComponent( SqlSessionFactory sqlSessionFactory )
{
    MyBatisComponent result = new MyBatisComponent();
    result.setSqlSessionFactory( sqlSessionFactory );
    return result;
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38292022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档