【发布时间】:2010-04-04 09:32:04
【问题描述】:
问题继续(struts 2 bean is not created) 我在 Tomcat 下的非常简单的 Web 应用程序中使用 struts2 + toplink。 在页面上我想使用迭代标签。这就是为什么我声明了一些工厂(SomeFactory)来解析实体(Entity)的集合。 每篇文章:http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28221/usclient005.htm#CIHCEHHG 我唯一需要的是声明:
@PersistenceContext(unitName="name_in_persistence_xml")
public class SomeFactory
{
@PersistenceUnit(unitName="name_in_persistence_xml")
EntityManagerFactory emf;
public EntityManager getEntityManager() {
assert(emf != null); //HERE every time it is null
return emf.createEntityManager();
}
public Collection<Entity> getAll()
{
return getEntityManager().createNamedQuery("Entity.findAll").getResultList();
}
}
怎么了?可能我错过了 web.xml 中的某些内容吗?如何为 Web 应用预初始化 toplink 以允许注入?
【问题讨论】:
标签: java jpa dependency-injection struts toplink-essentials