Skip to content

ClassPathMapperScanner scan mappers interface do not check if it contains @Mapper annotation #245

Closed
@maxjiang153

Description

@maxjiang153

when scan interfaces it will proxy all interface even it does not contains @Mapper interface.

https://github.com/mybatis/spring/blob/master/src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java#L216

  protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
    return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();
  }


  should be check has @Mapper annotation like this?
  protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
    return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent() 
                    &&  beanDefinition.getMetadata().hasAnnotation(Mapper.class.getName()); 
  }

example :

interface Example {
....
}

will create MapperFactoryBean proxy without @Mapper

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions