使用Spring/Struts/OpenJPA时遇到初始Spring注入的Struts Action与运行时取得的不是一个:
1. applicationContext.xml
[code="xml"]...
<!-- Struts Actions -->
class="com.example.myproject.view.AuthorAction">
<!-- Business Services -->
<bean id="authorService" class="com.example.myproject.service.AuthorServiceImpl">
<property name="authorDao" ref="authorDao"/>
</bean>
<!-- Data Access Objects -->
<bean id="authorDao" class="com.example.myproject.persistence.dao.AuthorDAOImpl">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
...[/code]
2. AuthorAction.java
[code="java"]public class AuthorAction extends DispatchAction {
private AuthorService authorService;
public AuthorService getAuthorService() {
return authorService;
}
public void setAuthorService(AuthorService authorService) {
this.authorService = authorService;
}
public ActionForward list(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) {
List<Author> result = authorService.findByName("hello");
request.setAttribute(Constant.LIST, result);
return mapping.findForward(Constant.FWD_LIST);
}
...
}
[/code]
调试AuthorAction.Java,将断点设在第9行和第15行,得到的两个不同的AuthorAction实例(请见附图)。请问这是什么原因,如何才能改对?