AOP AspectJ静态字段初始化,带有Annotated(标记)类

时间:2012-08-10 08:12:18

标签: java static annotations aop aspectj

我有一个静态字段public static Class[] items;我希望在应用程序的开头填充具有@ItemExample注释的类。示例类(简化):

public class ItemUtil{
public static Class[] itemClasses;
public static void actionsWithAllItemClasses(
//call some general method of classes in array using reflection API
)
}



  @ItemExample
    public class Item1 extends GeneralItem{
     public static void generalMethod(){
    //Item 1 specific action
        }
    }

    @ItemExample
    public class Item2 extends GeneralItem{
    public static void generalMethod(){
    //Item2 specific action
         }
    }

所以在启动时(部署,在ServletCOntextListneres开始执行之前)应用程序的时间(在Tomcat中运行)item classes=={Item1.class, Item2.class}。另外我希望每个类都覆盖generalMethod()的{​​{1}},但这个方法是静态的,所以每个类都声明它自己的方法。

1 个答案:

答案 0 :(得分:1)

Google Reflections运行时搜索和

Evo Class Index编译时间搜索

有帮助。