MyBatisマッパーが '[com.study.dal。***。mapper]'パッケージに見つかりませんでした

MapperScannerConfigurerを使用してマッパーの下のファイルを自動的にスキャンすると、次の警告が常に表示されます:MyBatisマッパーが '[com.study.boot.dal。* .Mapper]'パッケージに見つかりませんでした。
マッパーに登録されているファイルはありません

設定は以下の通りです

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFaction" />
        <property name="annotationClass" value="javax.annotation.Resource" />
        <property name="basePackage" value="com.study.boot.dal.***.mapper" />
    </bean>

その理由は次のとおりです。annotationClass構​​成の増加により、Resourceによって注釈が付けられたファイルのみがスキャンされるため、この構成をコメントアウトするだけで問題ありません。

変更された構成は次のとおりです

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFaction" />
        <property name="basePackage" value="com.study.boot.dal.***.mapper" />
    </bean>

annotationClassを使用したソースコードは次のとおりです。

protected void registerDefaultFilters() {
      boolean acceptAllInterfaces = true;
      // if specified, use the given annotation and / or marker interface
      if (MapperScannerConfigurer.this.annotationClass != null) {
        addIncludeFilter(new AnnotationTypeFilter(MapperScannerConfigurer.this.annotationClass));
        acceptAllInterfaces = false;
      }

      // override AssignableTypeFilter to ignore matches on the actual marker interface
      if (MapperScannerConfigurer.this.markerInterface != null) {
        addIncludeFilter(new AssignableTypeFilter(MapperScannerConfigurer.this.markerInterface) {
          @Override
          protected boolean matchClassName(String className) {
            return false;
          }
        });
        acceptAllInterfaces = false;
      }

      if (acceptAllInterfaces) {
        // default include filter that accepts all classes
        addIncludeFilter(new TypeFilter() {
          public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
            return true;
          }
        });
      }
    }
190件の元の記事を公開 19件の賞賛 200,000回以上の閲覧

おすすめ

転載: blog.csdn.net/zengchenacmer/article/details/78336512