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);
}
}
}