Hello I am trying to write a custom annotation for a Spring MVC webapp.But somehow annotated classes are not getting detected by Spring applicationContext.Here is my relevent code.
Annotated class:
CustomAnnotationDefinition:Code:@Component @MigrationRequired(migrateFrom="Tiff",migrateTo="PDF-A") public class WordTemplate extends Template{ }
Class for detecting Annotation on ContextLoadingCode:@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface MigrationRequired { String migrateFrom() default "Tiff"; String migrateTo() default "PDF-A"; }
applicationContext.xml relevant configurationCode:public class MigrationHandler implements ApplicationContextAware, InitializingBean { private ApplicationContext applicationContext; @Override public void afterPropertiesSet() throws Exception { final Map<String, Object> myMaps = applicationContext.getBeansWithAnnotation(MigrationRequired.class); System.out.println("inside after properties set" + myMaps );//**Always giving an empty set** for (final Object myMap : myMaps.values()) { final Class<? extends Object> myClass = myMap .getClass(); final MigrationRequired annotation = myClass .getAnnotation(MigrationRequired.class); System.out.println("Found myClass: " + myClass + ", with tags: " + annotation.migrateFrom()); } } @Override public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { System.out.println("This is called"); this.applicationContext = applicationContext; } }
So in method of MigrationHandler afterPropertiesSet()I am always getting myMaps as empty. Am I doing something wrong? Thank you.Code:<bean id="migrationHandler" class="com.test.annotation.MigrationHandler"/> <context:component-scan base-package="com.test" > <context:include-filter type="annotation"expression="com.test.annotation.MigrationRequired"/> </context:component-scan> <!--Other beans definition-->


Reply With Quote
