昨天继续学习夏老大的《Spring 开发指南》,发现一个比较大的bug。27页中
ApplicationContext ctx
=
new
FileSystemXmlApplicationContext(
“
bean.xml
“
);
LoginAction action
=
(LoginAction)ctx.getBean(
“
action
“
);
action.login(
“
Erica
“
,
“
mypass
“
);
<
bean id
=
“
loginaction
“
class
=
“
net.xiaxin.beans.LoginAction
“
/>
<
bean id
=
“
listener
“
class
=
“
net.xiaxin.beans.ActionListener
“
/>
ApplicationContext ctx
=
new
FileSystemXmlApplicationContext(
“
bean.xml
“
);
LoginAction action
=
(LoginAction)ctx.getBean(
“
action
“
);
action.login(
“
Erica
“
,
“
mypass
“
);
之前bean.xml中定义的bean为
<
bean id
=
“
loginaction
“
class
=
“
net.xiaxin.beans.LoginAction
“
/>
<
bean id
=
“
listener
“
class
=
“
net.xiaxin.beans.ActionListener
“
/>
一个非常明显的bean名称调用错误,应该使用loginaction,而不是action。
不知道这个错误是夏老大犯的还是出版社弄的,还是我在网上下的资料不准确呢?
不过这对我这样的spring初学者是有好处的。