All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nh.micro.dao.mapper.scan.Scanner Maven / Gradle / Ivy

There is a newer version: 1.2.5-RELEASE
Show newest version
package com.nh.micro.dao.mapper.scan;



import java.io.IOException;
import java.util.Set;

import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.TypeFilter;

import com.nh.micro.dao.mapper.NDaoMapperFactory;





public class Scanner extends ClassPathBeanDefinitionScanner {
	  public Scanner(BeanDefinitionRegistry registry) {
	      super(registry);
	  }
	  public void registerDefaultFilters() {
		  this.addIncludeFilter(new TypeFilter() {
		        @Override
		        public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
		        	//add 201806 ninghao
			          boolean flag=metadataReader.getAnnotationMetadata().hasAnnotation("com.nh.micro.dao.mapper.InjectDao");
			          return flag;
		        }
		      });
		  
	  }
	  public Set doScan(String... basePackages) {
	      Set beanDefinitions =   super.doScan(basePackages);
	      for (BeanDefinitionHolder holder : beanDefinitions) {
	          GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
	          definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
	          definition.setBeanClass(NDaoMapperFactory.class);
	      }
	      return beanDefinitions;
	  }


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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy