Back Forum Reply New

Implementing BeanNameAware interface

Hi ,

I have read why to implement BeanNameAware and override the setBeanName()
I still could not understand the use of implementing BeanNameAwareA code snippet :
Code:
public class BeanLifeCycleTestBean implements BeanNameAware{
   String beanName;
   public void setBeanName(String beanName) {       this.beanName = beanName;   }
   public String getBeanName(){       return beanName;   }

}
lt;bean id=quot;testquot; class=quot;net.agilejava.jedi.spring.beanLifeCycle.Bea  nLifeCycleTestBeanquot; /gt;Code:
public class BeanLifeCycleTest {
   private ApplicationContext context;
   public void BeanNameAware() {       context = new ClassPathXmlApplicationContext(quot;net/agilejava/jedi/spring/beanLifeCycle/applicationContext.xmlquot;);       BeanLifeCycleTestBean bean = (BeanLifeCycleTestBean) context.getBean(quot;testquot;);
        bean.getBeanName();   }

}
My query is that typically this is what we will do when calling a DAO from a servlet

from my Servlet we would call

ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicati  onContext(getServletContext());MyDao dao = (MyDAO) context.getBean(quot;mybeanquot;);

so please tell where is the diference .

Hey I am also new to Spring I am also looking for answer of this same query.
what is special of this interface. Why someone will call the setBeanName(String beanName) as we can define the name and id for the bean in the XML definition.

Thank
¥
Back Forum Reply New