re: Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解實(shí)例詳解(三)
2012-02-29 10:58 |
spring中已經(jīng)配置自動(dòng)掃描:
<context:component-scan base-package="cn.test"></context:component-scan>
Action類:
public class ShowAccountAction extends ActionSupport {
private static final long serialVersionUID = 1L;
@Autowired
private transient AccountService accountService;
頁(yè)面請(qǐng)求:
<s:url action="show-account" var="showAccountUrl">
<s:param name="username" value="%{'j2ee'}"/>
</s:url>
問(wèn)題:
1.如上代碼accountService為空, 也就是說(shuō)Spring無(wú)法注入
2.如果在Action類上加@Controller("show-account")然后
cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
ShowAccountAction showAccount= (ShowAccountAction)cxt.getBean("show-account");
accountService = showAccount.getAccountService();得到非空accountServic,此時(shí)也就是說(shuō)Spring可以注入
3綜合1、2說(shuō)明Action沒(méi)有被Spring托管
我看過(guò)您的Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解實(shí)例詳解,也十分想嘗試下注解,請(qǐng)您幫助解決下。
回復(fù) 更多評(píng)論