我想在 Java 中实现一个基于注解的初始化机制。具体来说,我定义了一个注释:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Initialization {
/**
* If the eager initialization flag is set to <code>true</code> then the
* initialized class will be initialized the first time it is created.
* Otherwise, it will be initialized the first time it is used.
*
* @return <code>true</code> if the initialization method should be called
* eagerly
*/
boolean eager() default false;
}
另外,我有一个界面:
public interface SomeKindOfBasicInterface {}
我想SomeKindOfBasicInterface
在我的类路径上找到该类的每个实现,该类在@Initialization
方法上有注释。我正在查看 Spring 的MetaDataReader
工具,这看起来像是在执行此操作时推迟加载其他实现的最佳方式SomeKindOfBasicInterface
......但我不确定如何像我描述的那样进行搜索。有小费吗?