0
我正在嘗試爲Liferay編寫一個portlet(使用Tomcat和Spring),並且需要通過Persistence API/Hibernate使用數據庫。我正在使用一些配置XML(applicationContext.xml等)和註釋來實現這一點。例如如何確定應用程序上下文中的對象?
@Component @Scope("application")
public class SomeForm {
@PersistenceContext EntityManager entityManager;
目前我遇到了NullPointerExceptions發生的一些麻煩,在我看來,因爲entityManager沒有綁定。但我並不是要求回答這個問題,而是要求更廣泛的主題:
是否有一種簡單的方法來檢查運行時(例如PesistenceContext,SessionContext)應用程序上下文中的對象是否可用以及如何確定一個對象在運行時綁定在應用程序上下文中?
這裏有一些信息:http://stackoverflow.com/questions/129207/getting-spring-application-context –