Home > Back-end >  Spring for the questions in the annotations of interfaces and classes
Spring for the questions in the annotations of interfaces and classes

Time:04-07

Custom an annotation @ HormDao, USES applicationContext. GetBeansWithAnnotation (HormDao. Class) can get annotated classes, can't get to the annotated interface, this is the reason why

 
@ HormDao
Public interface HormTestDao extends IBaseDao {

}

@ HormDao
Public class SpringDaoImpl {

}

@ Component
Public class BaseDaoRegisterBean implements ApplicationContextAware, BeanDefinitionRegistryPostProcessor {
Private BeanDefinitionRegistry registry;
Private ApplicationContext context;

@ Override
Public void postProcessBeanFactory (ConfigurableListableBeanFactory the beanFactory) throws BeansException {
}

@ Override
Public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry) throws BeansException {
This. Registry=registry;

Map Beans=context. GetBeansWithAnnotation (HormDao. Class);
For (Map. Entry Entry: beans. EntrySet ()) {
System. Out.println (entry. GetKey () + "- & gt;" + (entry. GetValue (). GetClass ()));
}
}

@ Override
Public void setApplicationContext (ApplicationContext ApplicationContext) throws BeansException {
Enclosing context=applicationContext;
}
}

CodePudding user response:

The interface cannot be instantiated, not in containers
  • Related