views:

89

answers:

1

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and annotations to realize that. e.g.

@Component @Scope("application")
public class SomeForm {
   @PersistenceContext EntityManager entityManager;

At the moment I am having some troubles with NullPointerExceptions which occur, in my opinion, because the entityManager is not bound. But I am not asking for an answer to that problem, but to a more wider topic:

Is there an easy way to check what Objects are available in the application context at runtime (e.g. PesistenceContext, SessionContext) and to determine how an Object is bound in the application context at runtime?

+1  A: 

You can call methods

getBeanDefinitionCount()
getBeanDefinitionNames()
getBeanNamesForType()
getBeansOfType()
getBean()

on the application context itself to inspect the beans it contains at runtime.

There are also equivalent static methods on the BeanFactoryUtils class that will take into account the nesting hierarchy if you are using nested contexts.

alasdairg