mapper.xmlパスMyBatisのプラスピット構成

春ブーツ統合MyBatisのプラスMySQLと彼は以下の質問に会ったときに、Oracleは、複数のデータソースを使用しました:

MyBatisのは、プラス今日はmapper.xmlファイルを読み取れませんMyBatisのされた問題が発生しました。

これによって、次のように質問があり、それを記録します。

org.apache.ibatis.binding.BindingException:無効バウンド声明(見つからない):com.husy.mapper.SystemUserMapper.findUserByName 

    com.baomidou.mybatisplus.core.override.MybatisMapperMethod $ SqlCommandオブジェクトで。<初期化>(MybatisMapperMethod.java:242 
    com.baomidou.mybatisplus.core.override.MybatisMapperMethodました。<init>(MybatisMapperMethod.java:54 
    com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda $ cachedMapperMethodで$ 0(MybatisMapperProxy.java:65 
    java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.javaで: 1660 
    com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.javaで:65 
    com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java時: 60 
    。com.sun.proxy $ Proxy72.findUserByName(不明なソース)で
    com.husy.service.impl.SystemUserServiceImpl.findUserByNameで(SystemUserServiceImpl.java: 23)

まず、私は、XMLパッケージは問題ありません置くが、棚のパッケージや構成の問題が導入された、として設定問題は次のとおりです。

MyBatisの:
  マッパー -locations:クラスパス:マッパー/ * .xmlの
  型のエイリアスパッケージ:com.msl.moniter.entity

ソリューション:3回を言うためにしてくださいMyBatisのプラスMyBatisの中、MyBatisの、mybtis、重要なのは、

必要に応じてパケットフレーム

<依存性> 
<のgroupId> com.baomidou </のgroupId>
<たartifactId> MyBatisのプラスブートスターター</たartifactId>
<バージョン> 3.1.2 </バージョン>
</依存>
<依存性>
<のgroupId> com.baomidou </のgroupId>
<たartifactId> MyBatisのプラスコア</たartifactId>
<バージョン> 3.1.2 </バージョン>
</依存>
<依存性>
<のgroupId> org.mybatis.spring.boot </のgroupId>
<たartifactId> MyBatisのスプリング・ブート・自動設定</たartifactId>
<バージョン> 2.1.0 </バージョン>
</依存関係>

最初のものはMyBatisのスプリング・ブート開始されることに注意してください、ないmybatisplusスプリング・ブート開始

また、声明の中でこのような問題を解決し、MyBatisの設定ファイルをMybatisSqlSessionFactoryBean

@Configuration
 パブリック クラスMybatisPlusConfig { 
    @Autowired 
    プライベートデータソースのdataSource。

    @Autowired 
    プライベートMybatisPropertiesのプロパティ; 

    @Autowired 
    プライベート ResourceLoader resourceLoader = 新しいDefaultResourceLoader(); 

    @Autowired(必須 = プライベートインターセプター[]インターセプタ。

    (必要な@Autowired = プライベートDatabaseIdProvider databaseIdProvider。

    / ** 
     * MyBatisのプラス分页插件
     * / 
    @Bean 
    公衆PaginationInterceptor PaginationInterceptor(){ 
        PaginationInterceptorページ = 新新PaginationInterceptor(); 
        page.setDialectType( "MySQLの" );
         リターンページ; 
    } 
    / ** 
     *ここでは、すべて、すでにMyBatisの-自動構成が自動的にロードされたリソースを使用します。手動で指定されていませ
     * MyBatisのブート構成ファイルと設定ファイルの同期を
     * @return 
     * / 
    @Bean 
    公共MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean(){ 
        MybatisSqlSessionFactoryBean mybatisPlus = 新新)MybatisSqlSessionFactoryBean(; 
        mybatisPlus.setDataSource(データソース);
        mybatisPlus.setVfs(SpringBootVFS。クラス);
        もし(StringUtils.hasText(この.properties.getConfigLocation())){ 
            mybatisPlus.setConfigLocation(この .resourceLoader.getResource(この.properties.getConfigLocation()))。
        } 
        mybatisPlus.setConfiguration(properties.getConfiguration())。
        もし(!ObjectUtils.isEmpty(この.interceptors)){ 
            mybatisPlus.setPlugins(この.interceptors)。
        } 
        MybatisConfiguration MC = 新しいMybatisConfiguration()。
        mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver。クラス); 
        mybatisPlus.setConfiguration(MC)。
        もしこの!.databaseIdProvider = ヌル){ 
            mybatisPlus.setDatabaseIdProvider(この.databaseIdProvider)。
        } 
        であれば(StringUtils.hasLength(この.properties.getTypeAliasesPackage())){ 
            mybatisPlus.setTypeAliasesPackage(この.properties.getTypeAliasesPackage())。
        } 
        であれば(StringUtils.hasLength(この.properties.getTypeHandlersPackage())){ 
            mybatisPlus.setTypeHandlersPackage(この.properties.getTypeHandlersPackage()); 
        } 
        もし!(ObjectUtils.isEmpty(この .properties.resolveMapperLocations())){ 
            mybatisPlus.setMapperLocations(この.properties.resolveMapperLocations())。
        } 
        戻りmybatisPlusと、
    } 
}

 

何の検証によるがないように私は、大げさ不正確またはjar問題を知りません

へのアクセスを通じ:

  • もし参照MyBatisのプラスブートスターター依存のconfigure MyBatisの-plus.mapper-場所
  • 参照が依存MyBatisのプラスの場合は、configure mybatis.mapper-場所

 

参考:

https://blog.csdn.net/u013234928/article/details/94060733

https://blog.csdn.net/qq_21747795/article/details/81217264

おすすめ

転載: www.cnblogs.com/Sincerity/p/11990445.html