当前使用版本(必填,否则不予处理)
3.4.0
该问题是如何引起的?(确定最新版也有问题再提!!!)
MybatisSqlSessionFactoryBean第474行
GlobalConfigUtils.setGlobalConfig(targetConfiguration, this.globalConfig);
若MybatisConfiguration在上述代码执行之前被创建bean,MybatisConfiguration.setGlobalConfig会被spring自动调用,且上续474行的targetConfiguration的hashCode与提前创建好的bean相同,此时474行执行无效;导致无法设置metaObjectHandler,insertFill updateFill就都不起作用了
对比版本发现,上述逻辑是3.4.0加上去的,版本回退至3.3.2正常;
重写 GlobalConfigUtils.setGlobalConfig 方法将putIfAbsent改成put也可以解决;
报错信息
metaObjectHandler注入无效,insertFill updateFill就都不起作用了
Comment From: miemieYaho
不支持你这么搞
Comment From: heylear
不支持你这么搞
最简复现: MainApplication.java
@SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } }
application.properties
spring.datasource.url=url... spring.datasource.username=user... spring.datasource.password=pwd...
注意这里,加上后insertFill就不再起作用!!!
mybatis-plus.configuration.global-config.banner=false
DemoEntity.java
@Getter @Setter @TableName("t_demo") public class DemoEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Long id;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
@TableField(select = false)
private Integer isDeleted;
}
DemoMapper.java
@Mapper
public interface DemoMapper extends BaseMapper
DemoTest.java
@Component
@RequiredArgsConstructor
public class DemoTest implements ApplicationListener
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
demoMapper.insert(new DemoEntity());
}
}
这个例子中,只要配置文件中配置了mybatis-plus.configuration.global-config前缀的任何属性,insertFill就会失效,因为只要配置了,MybatisConfigruation.setGlobalConfig就会被调用,之后再去调用GlobalConfigUtils.setGlobalConfig就无法覆盖了;
@miemieYaho 你看下