不管是在Spring还是Mybatis中,我们都需要配置一个包路径进行扫描类对象。
在Spring中,我们需要配置包路径,让Spring容器能扫描包下面的Bean组件。在mybatis中,我们需要配置mapper包路径,以扫描mapper接口,并生成对应的Bean实例。
现在,我参照spring的部分源码,来写一个工具类扫描包及子包下的所有类。
package com.company.handler;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.env.Environment;
import org.springf