通过注解,扫描加载指定路径下的所有注解定义的规则类,实现方法。
思想:
扫描注册,映射匹配。
优势:
解耦,代码易读,组件化等等
应用场景和具体实现大家可自行摸索。
以下为示例代码,提供思路,可自行修改。
方法一:扫描class文件,通过反射实例化对象,适合有状态对象。
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.stereotype.Component;
import com.***.***.RectificationLogBuild;
/**
* 通过注解获取规则类
* @author 天才之上
*