Spring.xml的代码: <bean id="getProductAction" class="action.getProductAction">
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>
<bean id="productAction" class="action.productAction">
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>
Action里的代码:
private IProductBiz productBiz = null;
private int id;
public String execute() throws Exception {
Product product = new Product();
product = productBiz.findById(id);
Map session = ActionContext.getContext().getSession();
session.put("product", product);
return SUCCESS;
}
public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
private IProductBiz productBiz = null;
public String execute() throws Exception {
List<Product> newList = new ArrayList<Product>();
newList = productBiz.findByTime();
Map session = ActionContext.getContext().getSession();
session.put("newProducts", newList);
List<Product> pList = new ArrayList<Product>();
pList = productBiz.findAll();
session.put("products", pList);
return SUCCESS;
}
public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
}
问题是getProduct的Action里面的productBiz能实例化~但是到了product的Action里面的productBiz却为空~~以前做别的Spring里面两个同样的依赖注入都没有问题~但是现在做这个不知道为什么~Spring里面两个同样的注入就只有第一个能实例化.后面加入的都是为空~调试时候setter里面获取到接口的实例化但是到了方法运行又为空了~求高手解决~新手坐等~ |