Reflections 通过扫描 classpath, 索引元数据, 并且允许在运行时查询这些元数据.
使用 Reflections 可以很轻松的获取以下元数据信息:
获取某个类型的所有子类; 比如, 有一个父类是 TestInterface, 可以获取到 TestInterface 的所有子类.
获取某个注解的所有类型 / 字段变量, 支持注解参数匹配.
使用正则表达式获取所有匹配的资源文件.
获取特定签名方法.
一, 引入依赖
因 Reflections 框架依赖 com.google.guava, 所以也需导入.
- <dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
- <version>0.9.11</version>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>23.0</version>
- </dependency>
来源: http://www.bubuko.com/infodetail-3461282.html