A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 狄琛林 中级黑马   /  2012-9-21 18:07  /  1323 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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里面获取到接口的实例化但是到了方法运行又为空了~求高手解决~新手坐等~

评分

参与人数 1技术分 +1 收起 理由
刘芮铭 + 1 赞一个!

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马