Spring beans: ApplicationContextFactory

This code snipped shows you how to get a bean from the applicationContext.xml

<bean id="statusDao" parent="baseTransactionProxy">
<property name="target">
<bean class="com.xyz">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</property>
</bean>


package com.xyz;

import org.springframework.beans.factory.xml.XmlBeanFactory;

public class Xyz
{
    public static void main(String[] args)
    {
XmlBeanFactory beans = ApplicationContextFactory.getXmlBeanFactoryInstance();
                   setBeanManager((PersistentBeanManager) application.getBean("hibernateBeanManager"));
        StatusDao statusDao = (StatusDao) beans.getBean("statusDao");

Status status = statusDao.fetch(new Long(1));
System.out.print(status.getEntity());
    }
}

No comments:

Post a Comment