Java annotation scanning with spring

后端 未结 4 1498
Happy的楠姐
Happy的楠姐 2021-01-07 04:37

I have few classes that I need to annotate with a name so I defined my annotation as

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @i         


        
4条回答
  •  半阙折子戏
    2021-01-07 05:03

    Just get the annotation object and pull out the value

    Map tmpMap = new HashMap();
    JsonUnmarshallable ann;
    for (T o : applicationContext.getBeansWithAnnotation(annotationType).values()) {
        ann = o.getClass().getAnnotation(JsonUnmarshallable.class);
        tmpMap.put(ann.value(),o);
    }
    return o;
    

    Let me know if that's not clear.

提交回复
热议问题