1.属性注入(set注入)
(1)在对应的action中给set/get方法
private StuBiz stuBiz;
public StuBiz getStuBiz() { return stuBiz; } public void setStuBiz(StuBiz stuBiz) { this.stuBiz = stuBiz; }
(2)在application的配置:
<bean id="stuAction" class="com.yangkang.action.StuAction" scope="prototype">
<property name="stuBiz" ref="stuBiz"/>
</bean>
2.构造器注入
(1)在对应的action中给构造方法
private StuBiz stuBiz;//属性
public StuAction(StuBiz stuBiz) {//构造器 super(); this.stuBiz = stuBiz; }
(2)在application的配置:
<bean id="stuAction" class="com.yangkang.action.StuAction" scope="prototype"> <constructor-arg ref="stuBiz"></constructor-arg>//构造器注入的具体配置 </bean>