stripes spring annotation_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > stripes spring annotation

stripes spring annotation

 2014/5/2 16:07:44  zwhc  程序员俱乐部  我要评论(0)
  • 摘要:stripes源码阅读stripes-code-1527-tags-1.5.6\stripes\src\net\sourceforge\stripes\integration\spring\SpringHelper.javapublicstaticvoidinjectBeans(Objectbean,ApplicationContextctx){//Firstinjectanyvaluesusingannotatedmethodsfor(Methodm:getMethods(bean
  • 标签:not Annotation Spring
stripes 源码阅读

stripes-code-1527-tags-1.5.6\stripes\src\net\sourceforge\stripes\integration\spring\SpringHelper.java

class="java">

    public static void injectBeans(Object bean, ApplicationContext ctx) {
        // First inject any values using annotated methods
        for (Method m : getMethods(bean.getClass())) {
            try {
                SpringBean springBean = m.getAnnotation(SpringBean.class);
                boolean nameSupplied = !"".equals(springBean.value());
                String name = nameSupplied ? springBean.value() : methodToPropertyName(m);
                Class<?> beanType = m.getParameterTypes()[0];
                Object managedBean = findSpringBean(ctx, name, beanType, !nameSupplied);
                m.invoke(bean, managedBean);
            }
            catch (Exception e) {
                throw new StripesRuntimeException("Exception while trying to lookup and inject " +
                    "a Spring bean into a bean of type " + bean.getClass().getSimpleName() +
                    " using method " + m.toString(), e);
            }
        }

        // And then inject any properties that are annotated
        for (Field f : getFields(bean.getClass())) {
            try {
                SpringBean springBean = f.getAnnotation(SpringBean.class);
                boolean nameSupplied = !"".equals(springBean.value());
                String name = nameSupplied ? springBean.value() : f.getName();
                Object managedBean = findSpringBean(ctx, name, f.getType(), !nameSupplied);
                f.set(bean, managedBean);
            }
            catch (Exception e) {
                throw new StripesRuntimeException("Exception while trying to lookup and inject " +
                    "a Spring bean into a bean of type " + bean.getClass().getSimpleName() +
                    " using field access on field " + f.toString(), e);
            }
        }
    }

发表评论
用户名: 匿名