解決mybatis+springboot+flowable6.4.0遇到的問題
問題
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
寫錯對應(yīng)關(guān)系 namespace等騷操作造成的就不說了。動動腦子。下面主要說沖突導致的這個問題。
源碼查看
1 報錯位置
MappedStatement ms = resolveMappedStatement(mapperInterface, methodName, declaringClass,
configuration);
if (ms == null) {
if (method.getAnnotation(Flush.class) != null) {
name = null;
type = SqlCommandType.FLUSH;
} else {
throw new BindingException("Invalid bound statement (not found): "
+ mapperInterface.getName() + "." + methodName);
}
...
2 ms為啥為空 因為 mappedStatements里沒有(MapperLocations配置沒生效)
private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String methodName,
Class<?> declaringClass, Configuration configuration) {
String statementId = mapperInterface.getName() + "." + methodName;
if (configuration.hasStatement(statementId)) {
return configuration.getMappedStatement(statementId);
} else if (mapperInterface.equals(declaringClass)) {
return null;
}
public boolean hasStatement(String statementName) {
return hasStatement(statementName, true);
}
public boolean hasStatement(String statementName, boolean validateIncompleteStatements) {
if (validateIncompleteStatements) {
buildAllStatements();
}
return mappedStatements.containsKey(statementName);
}
3 真正原因! @ConditionalOnMissingBean ?。。。。喝绻萜髦袥]有,就注入,如果有就不注入.mybatis的sqlsession被flowable的覆蓋了
mybatis的:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration里
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
...
factory.setMapperLocations(this.properties.resolveMapperLocations());
...
}
flowable的:org.flowable.ui.modeler.conf.DatabaseConfiguration里
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
String databaseType = this.initDatabaseType(dataSource);
if (databaseType == null) {
throw new FlowableException("couldn't deduct database type");
} else {
try {
Properties properties = new Properties();
properties.put("prefix", this.modelerAppProperties.getDataSourcePrefix());
properties.put("blobType", "BLOB");
properties.put("boolValue", "TRUE");
properties.load(this.getClass().getClassLoader().getResourceAsStream("org/flowable/db/properties/" + databaseType + ".properties"));
sqlSessionFactoryBean.setConfigurationProperties(properties);
sqlSessionFactoryBean.setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(this.resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml"));
sqlSessionFactoryBean.afterPropertiesSet();
return sqlSessionFactoryBean.getObject();
} catch (Exception var5) {
throw new FlowableException("Could not create sqlSessionFactory", var5);
}
}
}
4 很明顯,mybatis的配置被覆蓋了。吐槽一下flowable-ui的源碼!
解決辦法
就是兼顧 flowable和mybatis的配置
1 第一步 排除flowable的sqlsession注入:
在@ComponentScan里加入這樣的話。 @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = DatabaseConfiguration.class)
2 第二步 增加flowable的屬性配置等。application.properties里添加如下配置。加modeler-mybatis-mapping那個
mybatis.mapperLocations=classpath*:mapper/*/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml #這里就是配個空?;蛘吲渲脭?shù)據(jù)庫用戶名 username也行,不要瞎改哈(這個是查詢前綴-flowable) mybatis.configuration-properties.prefix = mybatis.configuration-properties.blobType = BLOB mybatis.configuration-properties.boolValue = TRUE
3 第三步,做到這直接啟動項目可能會報 act_de_model表找不到等錯誤。再一個@Configuration配置里加入以下bean的注入
@Bean
public Liquibase liquibase(DataSource dataSource) {
Liquibase liquibase = null;
Liquibase var5;
try {
DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName("ACT_DE_" + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName("ACT_DE_" + database.getDatabaseChangeLogLockTableName());
liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update("flowable");
var5 = liquibase;
} catch (Exception var9) {
throw new InternalServerErrorException("Error creating liquibase database", var9);
} finally {
}
return var5;
}
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
spring定時器@Scheduled異步調(diào)用方式
在Spring Boot中,@Schedule默認使用單線程執(zhí)行定時任務(wù),多個定時器會按順序執(zhí)行,為實現(xiàn)異步執(zhí)行,可以通過自定義線程池或?qū)崿F(xiàn)SchedulingConfigurer接口,使用自定義線程池可以保證多個定時器并發(fā)執(zhí)行2024-11-11
eclipse修改jvm參數(shù)調(diào)優(yōu)方法(2種)
本篇文章主要介紹了eclipse修改jvm參數(shù)調(diào)優(yōu)方法(2種),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02
淺析Java 數(shù)據(jù)結(jié)構(gòu)常用接口與類
本篇文章主要介紹了Java中的數(shù)據(jù)結(jié)構(gòu),Java工具包提供了強大的數(shù)據(jù)結(jié)構(gòu)。需要的朋友可以參考下2017-04-04
Spring Boot 集成 Sharding-JDBC + Mybatis-Plus 實現(xiàn)分庫分表功能
這篇文章主要介紹了Spring Boot 集成 Sharding-JDBC + Mybatis-Plus 實現(xiàn)分庫分表功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08
Spring?BOOT?AOP基礎(chǔ)應(yīng)用教程
這篇文章主要介紹了Spring?BOOT?AOP的使用,文章從相關(guān)問題展開全文內(nèi)容詳情,具有一定的參考價值,需要的小伙伴可以參考一下2022-07-07
Java?IO流之StringWriter和StringReader用法分析
這篇文章主要介紹了Java?IO流之StringWriter和StringReader用法分析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
Java獲取項目路徑方式System.getProperty(“user.dir“)
這篇文章主要介紹了Java獲取項目路徑方式System.getProperty(“user.dir“),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12

