No MyBatis mapper was found in '[com.study.dal.***.mapper]' package

When using MapperScannerConfigurer to automatically scan files under the mapper, the following warning always appears: No MyBatis mapper was found in '[com.study.boot.dal. * .Mapper]' package.
And there is no file registered with mapper

The configuration is as follows

<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>

The reason is: Due to the increased annotationClass configuration, only the files annotated by Resource will be scanned, so you only need to comment out this configuration to be ok

The modified configuration is as follows

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

The source code using annotationClass is as follows:

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;
          }
        });
      }
    }
Published 190 original articles · 19 praises · 200,000+ views

Guess you like

Origin blog.csdn.net/zengchenacmer/article/details/78336512