Yes.. I looked at this post and it didnt work.
I tried to register the bean in two ways and I dont get how I suppose to connect my pojo instance into it:
This is the bean:
Code:
public class SessionMDB
{
@PostConstruct
public void init() throws Exception
{
System.out.println("I am alive");
}
}
and this is how I am trying to create new instance of it and register it as a spring bean:
First way:
Code:
SessionMDB sessionMDB = new SessionMDB();
ClassPathXmlApplicationContext context = ApplicationContextSingleton.getApplicationContext();
GenericBeanDefinition beanDef = new GenericBeanDefinition();
beanDef.setBeanClass(SessionMDB.class);
context.getBeanFactory().registerSingleton("SessionMDB", beanDef);
second way:
Code:
SessionMDB sessionMDB = new SessionMDB();
ClassPathXmlApplicationContext context = ApplicationContextSingleton.getApplicationContext();
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();
beanFactory.registerBeanDefinition("SessionMDB", BeanDefinitionBuilder.rootBeanDefinition(SessionMDB.class.getName()).getBeanDefinition());
This is my ApplicationContextSingleton class:
Code:
public class ApplicationContextSingleton
{
static ClassPathXmlApplicationContext context;
private ApplicationContextSingleton()
{
}
public static ClassPathXmlApplicationContext getApplicationContext()
{
if (context == null)
{
context = new ClassPathXmlApplicationContext(Constants.APPLICATION_CONTEXT_XML);
}
return context;
}
}
any idea?
thanks,
ray.