034a7a31dc20c1e1bc0da556d3d140025fb5aebe
[JavaForFun] /
1 package de.spring.example;
2
3 import java.util.Map;
4 import org.springframework.beans.BeansException;
5 import org.springframework.beans.factory.InitializingBean;
6 import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
7 import org.springframework.context.ApplicationContext;
8 import org.springframework.context.ApplicationContextAware;
9
10
11 public class AnnotationsHandler implements ApplicationContextAware, InitializingBean {
12           private ApplicationContext applicationContext;
13            
14           @Override
15           public void afterPropertiesSet() {
16                   GenericBeanFactoryAccessor genericBeanFactoryAccessor = new GenericBeanFactoryAccessor(applicationContext);
17                   
18                   final Map<String, Object> transactionalClass = genericBeanFactoryAccessor.getBeansWithAnnotation(TransactionalN2A.class);
19
20                   for (final Object myFoo : transactionalClass.values()) {
21                           final Class<? extends Object> fooClass = myFoo.getClass();
22                           final TransactionalN2A annotation = fooClass.getAnnotation(TransactionalN2A.class);
23                           System.out.println("Found 1 foo class: " + fooClass + ", with tags: ");
24                   }
25           }
26
27           @Override
28           public void setApplicationContext(final ApplicationContext applicationContext)
29               throws BeansException {
30             this.applicationContext = applicationContext;
31           }
32         }
33