我的应用程序中有一个非常奇怪的bug。我面临的问题是,如果我在ServiceMix中运行我的应用程序,来自SimpleJdbcCall的结果集总是包含以前存储过程调用的所有先前值。
但是,在本地运行时,只存储最后一个值。
我的骆驼路线(有假名):
<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作为参数。
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很简单,如下所示:
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);
}
};如果我在本地运行我的骆驼路线的话:
如果在ServiceMix中运行它,则日志:
工件的使用版本和所有配置在双方都是相同的。有什么想法吗?这个问题背后的逻辑是什么?谢谢,格格利
发布于 2013-06-19 13:14:09
问题出现在我使用的DataSource后面:首先,我使用了使用池的commons.dbcp.BasicDataSource。当我将它改为spring.jdbc.SimpleDriverDataSource时,它就开始工作了。这一个总是请求一个新的连接到DB,而前面的使用它的连接池。然而,BasicDataSource仍然使用maven,但在SMX中没有->我还没有检查BasicDataSource的源,但是本地Maven依赖项和SMX中的依赖项之间唯一的区别是:在Maven中,我没有导入共用池,而这个包安装在SMX中。我想是有内部机制的,以防目录中没有共用池.
https://stackoverflow.com/questions/17188810
复制相似问题