spring中BeanPostProcessor之二:CommonAnnotationBeanPostProcessor(01)

在上篇博客中分享了InstantiationAwareBeanPostProcessor接口中的四个方法,分别对其进行了详细的介绍,在文末留下了一个问题,那就是postProcessProperties方法,说到此方法是用来进行属性填充的,并且引出了CommonAnnotationBeanPostProcessor类。

一、概述

CommonAnnotationBeanPostProcessor类在spring中是一个极其重要的类,它负责解析@Resource、@WebServiceRef、@EJB三个注解,既然要解析这三个属性,那么在CommonAnnotationBeanPostProcessor类中肯定要有这三个注解,下面看这段代码,

static { try { @SuppressWarnings("unchecked") Class<? extends Annotation> clazz = (Class<? extends Annotation>) ClassUtils.forName("javax.xml.ws.WebServiceRef", CommonAnnotationBeanPostProcessor.class.getClassLoader()); webServiceRefClass = clazz; } catch (ClassNotFoundException ex) { webServiceRefClass = null; } try { @SuppressWarnings("unchecked") Class<? extends Annotation> clazz = (Class<? extends Annotation>) ClassUtils.forName("javax.ejb.EJB", CommonAnnotationBeanPostProcessor.class.getClassLoader()); ejbRefClass = clazz; } catch (ClassNotFoundException ex) { ejbRefClass = null; } //添加@Resource注解 resourceAnnotationTypes.add(Resource.class); if (webServiceRefClass != null) {
//添加@WebServiceRef注解 resourceAnnotationTypes.add(webServiceRefClass); }
if (ejbRefClass != null) {
//添加@EJB注解 resourceAnnotationTypes.add(ejbRefClass); } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zydsfp.html