d05ba921da62869a16555ccc14abbe4e40346ffd
[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 import de.spring.example.annotation.CustomTransactional;
10
11
12 public class AnnotationsHandler implements ApplicationContextAware, InitializingBean {
13           private ApplicationContext applicationContext;
14            
15           @Override
16           public void afterPropertiesSet() {
17                   GenericBeanFactoryAccessor genericBeanFactoryAccessor = new GenericBeanFactoryAccessor(applicationContext);
18                   
19                   final Map<String, Object> transactionalClass = genericBeanFactoryAccessor.getBeansWithAnnotation(CustomTransactional.class);
20
21                   for (final Object myFoo : transactionalClass.values()) {
22                           final Class<? extends Object> fooClass = myFoo.getClass();
23                           final CustomTransactional annotation = fooClass.getAnnotation(CustomTransactional.class);
24                           System.out.println("Found foo class: " + fooClass + ", with tags: ");
25                   }
26           }
27
28           @Override
29           public void setApplicationContext(final ApplicationContext applicationContext)
30               throws BeansException {
31             this.applicationContext = applicationContext;
32           }
33         }
34