MetaObjectHandler not found
时间: 2023-09-23 14:11:38 浏览: 76
MetaObjectHandler not found是一个常见的错误,通常出现在使用Mybatis-Plus的时候。这个错误的原因是没有正确配置Mybatis-Plus的MetaObjectHandler。
解决这个问题的方法是在MybatisSqlSessionFactoryBean的配置中添加MetaObjectHandler。根据提供的引用内容,可以看到在第一次配置MybatisSqlSessionFactoryBean时,没有设置MetaObjectHandler的相关配置,导致错误的发生。下面是一个正确的配置示例:
@Autowired
private MybatisPlusProperties mybatisPlusProperties;
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource());
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setMapUnderscoreToCamelCase(true);
configuration.setDefaultEnumTypeHandler(EnumOrdinalTypeHandler.class);
sqlSessionFactoryBean.setConfiguration(configuration);
sqlSessionFactoryBean.setPlugins(new Interceptor[]{paginationInnerInterceptor()});
Resource[] resources = mybatisPlusProperties.resolveMapperLocations();
sqlSessionFactoryBean.setMapperLocations(resources);
sqlSessionFactoryBean.setMetaObjectHandler(metaObjectHandler()); // 添加MetaObjectHandler配置
return sqlSessionFactoryBean.getObject();
}
@Bean
public MetaObjectHandler metaObjectHandler() {
return new YourMetaObjectHandler(); // 替换为自定义的MetaObjectHandler类
}
这样配置后,就能正确加载MetaObjectHandler,解决MetaObjectHandler not found的问题。请注意将YourMetaObjectHandler替换为自己定义的MetaObjectHandler类。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Java--springboot:配置 MybatisSqlSessionFactoryBean 报Invalid bound statement (not found)](https://blog.csdn.net/qq_31324077/article/details/130710654)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文