我正在尝试为 Liferay(使用 Tomcat 和 Spring)编写一个 portlet,并且需要通过 Persistence API/Hibernate 使用数据库。我正在使用一些配置 XML(applicationContext.xml 等)和注释来实现这一点。例如
@Component @Scope("application")
public class SomeForm {
@PersistenceContext EntityManager entityManager;
目前我遇到了一些 NullPointerExceptions 问题,在我看来,这是因为 entityManager 未绑定。但我不是要回答这个问题,而是要一个更广泛的话题:
是否有一种简单的方法可以在运行时检查应用程序上下文中可用的对象(例如,PesistenceContext、SessionContext)并确定对象在运行时如何绑定到应用程序上下文中?