首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SimpleJdbcCall/SimpleJdbcCall在ServiceMix中有状态

SimpleJdbcCall/SimpleJdbcCall在ServiceMix中有状态
EN

Stack Overflow用户
提问于 2013-06-19 10:22:20
回答 1查看 749关注 0票数 0

我的应用程序中有一个非常奇怪的bug。我面临的问题是,如果我在ServiceMix中运行我的应用程序,来自SimpleJdbcCall的结果集总是包含以前存储过程调用的所有先前值。

但是,在本地运行时,只存储最后一个值。

我的骆驼路线(有假名):

代码语言:javascript
复制
        <from ref="cronQuartzEndpoint"/>
        <to uri="bean:userDAO?method=listAll"/>

        <split>
            <simple>${body}</simple>
            <to uri="bean:myStoredProcCaller?method=requestAndStoreUserName" />
            <to uri="bean:userDAO?method=saveUser" />
        </split>

让我们看看存储过程调用逻辑。假设存储过程返回用户名,并等待id作为参数。

代码语言:javascript
复制
public User requestAndStoreUserName(User user) {
    LOG.info("userId: " + user.getId());

    //I know it's not necessary but I added it to ensure that new RowMapper is generated
    mySimpleJdbcCall.returningResultSet(USER_NAME_FIELD, new UserNameRowMapper());
    mySimpleJdbcCall.compile();

    Map<String, Object> results = mySimpleJdbcCall.execute(user.getId());

    List<String> userNames = (List<String>)results.get(USER_NAME_FIELD);
    LOG.info("userNames: " + userNames );
    if ( !userNames .isEmpty() ) {
        user.setName(userNames.get(0));
    }
    return user;
}

我的RowMapper很简单,如下所示:

代码语言:javascript
复制
private static class UserNameRowMapper implements RowMapper<String> {
    @Override
    public String mapRow(ResultSet rs, int rowNum) throws SQLException {
        return rs.getString(USER_NAME_RESPONSE_FIELD_INDEX);
    }
};

如果我在本地运行我的骆驼路线的话:

  • userId: 1
  • userNames:爱丽丝
  • userId: 2
  • userNames:鲍勃

如果在ServiceMix中运行它,则日志:

  • userId: 1
  • userNames:爱丽丝
  • userId: 2
  • userNames:爱丽丝,鲍勃

工件的使用版本和所有配置在双方都是相同的。有什么想法吗?这个问题背后的逻辑是什么?谢谢,格格利

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-19 13:14:09

问题出现在我使用的DataSource后面:首先,我使用了使用池的commons.dbcp.BasicDataSource。当我将它改为spring.jdbc.SimpleDriverDataSource时,它就开始工作了。这一个总是请求一个新的连接到DB,而前面的使用它的连接池。然而,BasicDataSource仍然使用maven,但在SMX中没有->我还没有检查BasicDataSource的源,但是本地Maven依赖项和SMX中的依赖项之间唯一的区别是:在Maven中,我没有导入共用池,而这个包安装在SMX中。我想是有内部机制的,以防目录中没有共用池.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17188810

复制
相关文章

相似问题

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