Announcement Announcement Module
Collapse
No announcement yet.
Beans modified in ApplicationListener are not reflcted when injected into other beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beans modified in ApplicationListener are not reflcted when injected into other beans

    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

    HTML 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>
    Role.java

    Code:
    private String planName;
    public String getPlanName() {
    		return planName;
    	}
    	
    	public void setPlanName(String planName) {
    		this.planName = planName;
    	}


    ApplicationContextListener

    Code:
    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
    
                    }
            }
    }
    When I inject this bean (id="defaultPlan") into another bean which is either applicationContext or dispatcher-servlet, values are not reflected
Working...
X