re: Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解實例詳解(三)
2012-02-29 10:58 |
spring中已經(jī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;
頁面請求:
<s:url action="show-account" var="showAccountUrl">
<s:param name="username" value="%{'j2ee'}"/>
</s:url>
問題:
1.如上代碼accountService為空, 也就是說Spring無法注入
2.如果在Action類上加@Controller("show-account")然后
cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
ShowAccountAction showAccount= (ShowAccountAction)cxt.getBean("show-account");
accountService = showAccount.getAccountService();得到非空accountServic,此時也就是說Spring可以注入
3綜合1、2說明Action沒有被Spring托管
我看過您的Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解實例詳解,也十分想嘗試下注解,請您幫助解決下。
回復 更多評論