MySQL使用mybatis读取json类型数据
问题描述
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySqlSessionFactory' defined in class path resource [com/plat/historydatastorage/utils/ds/DynamicDataSourceRegister.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'mySqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\ajj_project\his-data-storage\target\classes\mapper\his\MeasureDataMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [E:\ajj_project\his-data-storage\target\classes\mapper\his\MeasureDataMapper.xml]'. Cause: java.lang.IllegalStateException: No typehandler found for property valueExt
实体类属性:
private Map<String,Object> valueExt;
解决方法:
com.plat.historydatastorage.config.mybatisjava.sql.CallableStatementjava.sql.PreparedStatementjava.sql.ResultSetjava.sql.SQLExceptioncom.fasterxml.jackson.annotation.com.fasterxml.jackson.annotation.com.fasterxml.jackson.core.JsonGeneratorcom.fasterxml.jackson.databind.DeserializationFeaturecom.fasterxml.jackson.databind.ObjectMappercom.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidatororg.apache.ibatis.type.BaseTypeHandlerorg.apache.ibatis.type.JdbcTypeJsonTypeHandler<Object> BaseTypeHandler<> { ObjectMapper = ObjectMapper(){ .configure(DeserializationFeature.).configure(JsonGenerator.Feature.).setDefaultPropertyInclusion(.Include.).activateDefaultTyping( LaissezFaireSubTypeValidator.ObjectMapper.DefaultTyping..As.)} Class<> (Class<> clazz) { (clazz == ) {IllegalArgumentException()} .= clazz} (PreparedStatement psiparameterJdbcType jdbcType) SQLException { ps.setString(i.toJson(parameter))} (ResultSet rsString columnName) SQLException { .toObject(rs.getString(columnName))} (ResultSet rscolumnIndex) SQLException { .toObject(rs.getString(columnIndex))} (CallableStatement cscolumnIndex) SQLException { .toObject(cs.getString(columnIndex))} String (object) { { .writeValueAsString(object)} (Exception e) { RuntimeException(e)} } (String contentClass<?> clazz) { (content != && !content.isEmpty()) { { () .readValue(contentclazz)} (Exception e) { RuntimeException(e)} } { } } }