我在調用struts動作中的EJB對象時遇到問題。在Struts中調用EJB對象Action
我在glassfish中部署我的應用程序,在glassfish管理控制檯的應用程序描述中我看到有一個StatelessSessionBean被部署。我的應用程序的.ear文件包含.war(web模塊)和.jar(ejb),一個消息驅動,一個會話bean。
當我嘗試在struts動作類中調用會話bean時,我得到了空指針異常。
這裏是我的電話:
@EJB
private AccountFacade accountFacade;
@Override
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
UserCreationForm userCreationForm = (UserCreationForm) form;
Account account = new Account();
account.setName(userCreationForm.getName());
account.setEmail(userCreationForm.getEmail());
account.setPassword(userCreationForm.getPassword());
accountFacade.create(account);
return mapping.findForward(NavigationUtils.ACTION_SUCCESS);
}
異常發生在這條線:accountFacade.create(account);
帳戶外觀類看起來是這樣的:
@Stateless
public class AccountFacade extends AbstractFacade<Account> implements AccountFacadeLocal {
/**
* Persistence context entity manager.
*/
@PersistenceContext(unitName = "SearchEnginePU")
private EntityManager em;
/**
* Gets entity manager.
*
* @return entity manager.
*/
@Override
protected EntityManager getEntityManager() {
return em;
}
/**
* Constructor.
*/
public AccountFacade() {
super(Account.class);
}
}
AccountFacadeLocal接口:
@Local
public interface AccountFacadeLocal {
void create(Account account);
void edit(Account account);
void remove(Account account);
Account find(Object id);
List<Account> findAll();
int count();
}
我在這裏錯過了什麼?
謝謝,你幫我解決了我的問題。這是我第一次在struts應用程序中使用EJB,所以我不知道這一點。我使用JNDI查找,每一個作品都很好。 – 2012-04-18 19:39:41