How is the Mapper interface managed by Spring

  • 1. Use @mapperscan to scan for the corresponding interface
  • 2. Dynamically proxy the interface. All the proxy class does is take the SQL, connect to the database, and execute the SQL
  • 3. Through the Spring extension mechanismFactoryBeanHand the proxy object over to Spring to manage

Why does mapper work without the @Component annotation

    1. ClassPathMapperScannerimplementationspringtheClassPathBeanDefinitionScanner
  • In 2.registerFiltersMethod does the following thing, and this is springClassPathBeanDefinitionScannerindoScanMethod is used to determine whether packaging is requiredBeanDifitionSo it will scan all the @mappersacn configuration packets
addIncludeFilter(new TypeFilter() { @Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException { return true; }});Copy the code
  • 3. So there is no need to configure the @Component annotation on the Mapper interface