stripes spring annotation
程序员文章站
2022-07-15 12:45:45
...
stripes 源码阅读
stripes-code-1527-tags-1.5.6\stripes\src\net\sourceforge\stripes\integration\spring\SpringHelper.java
stripes-code-1527-tags-1.5.6\stripes\src\net\sourceforge\stripes\integration\spring\SpringHelper.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); } } }