【发布时间】:2010-10-14 03:31:28
【问题描述】:
我想在 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 实现的最佳方式......但我不确定如何像我一样进行搜索描述。有什么建议吗?
【问题讨论】:
标签: java spring annotations