I have a bean in applicationContext.xml which parent ApplicationContext.
I have implemented ApplicationListener which take a bean from context and initialize it with values from db.
Now, when I inject this bean into another bean, values are not reflected.
applicationContext.xml
Role.javaHTML Code:<bean id="defaultPlan" class="mwp.slktechlabs.model.Role" scope="singleton"> </bean> <bean id="roleDAO" class="mwp.slktechlabs.dao.RoleDAO"> <constructor-arg ref="roleCollection"></constructor-arg> </bean>
Code:private String planName; public String getPlanName() { return planName; } public void setPlanName(String planName) { this.planName = planName; }
ApplicationContextListener
When I inject this bean (id="defaultPlan") into another bean which is either applicationContext or dispatcher-servlet, values are not reflectedCode:public class ApplicationContextListener implements ApplicationListener { public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); if(applicationContext.getDisplayName().equals("Root WebApplicationContext")){ RoleDAO roleDao = (RoleDAO) applicationContext.getBean("roleDAO"); Role defaultPlan = (Role) applicationContext.getBean("defaultPlan"); //Converting json string to domain class Role through Jackson Lib defaultPlan = JSONUtils.objectFromJson(roleDao.getDefaultPlan().toString(), Role.class); //When I print default plan here, values are coming } } }


Reply With Quote
