问题描述
运行JdbcTemplate.update进行插入时出现以下错误。我正在使用JDK1.8。
java.lang.NoClassDefFoundError: org/springframework/util/LinkedCaseInsensitiveMap
at org.springframework.jdbc.core.ColumnMapRowMapper.createColumnMap(ColumnMapRowMapper.java:72)
at org.springframework.jdbc.core.ColumnMapRowMapper.mapRow(ColumnMapRowMapper.java:54)
at org.springframework.jdbc.core.ColumnMapRowMapper.mapRow(ColumnMapRowMapper.java:48)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:921)
at org.springframework.jdbc.core.JdbcTemplate$3.doInPreparedStatement(JdbcTemplate.java:910)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:639)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:910)
at io.bigbear.api.repository.FeatureDao.createFeature(FeatureDao.java:46)
at io.bigbear.api.services.FeatureService.createFeature(FeatureService.java:37)
以下是我的代码,我在第 jdbcTemplate.update(new PreparedStatementCreator():
final String sql = "INSERT INTO feature(feature,error,status,created_by,updated_by,created_dt,last_modified_dt,"
+ "job_id,entity_sk,feature_type,beNumber,osuffix) VALUES( ?,?,?)";
KeyHolder holder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = null;
ps = connection.prepareStatement(sql,new String[] { "feature_id" });
ps.setObject(1,feature.getFeature());
ps.setString(2,feature.getError());
ps.setString(3,feature.getStatus());
ps.setString(4,feature.getCreatedBy());
ps.setString(5,feature.getUpdatedBy());
ps.setTimestamp(6,feature.getCreatedDt());
ps.setTimestamp(7,feature.getUpdatedDt());
ps.setLong(8,feature.getJobId());
ps.setString(9,feature.getEntitySk());
ps.setString(10,feature.getFeatureType());
ps.setString(11,feature.getBeNumber());
ps.setString(12,feature.getOsuffix());
return ps;
}
},holder);
long newFeatureId;
if (holder.getKeys().size() > 1) {
newFeatureId = (Long) holder.getKeys().get("Feature_id");
} else {
newFeatureId = holder.getKey().longValue();
}
解决方法
我找到了原因,这是Spring DAO依赖项不匹配的原因之一。代码没有错。 谢谢。