Announcement Announcement Module
Collapse
No announcement yet.
Refreshing /Reloading a specific spring bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Refreshing /Reloading a specific spring bean

    Spring is providing a method by which we can dynamically REFRESH/RELOAD entire context .

    Create an ApplicationContextAware bean with following functions

    /**
    * setApplicationContext
    */
    public void setApplicationContext(ApplicationContext applicationContext)
    throws BeansException {
    this.applicationContext = applicationContext;

    }
    /**
    * refreshContext()
    */
    public void refreshContext(){
    ((ConfigurableApplicationContext)applicationContex t).refresh();
    }


    And call refreshContext() for the purpose.




    But how can we Refresh a SPECIFIC bean?

  • #2
    Originally posted by Sudheesh View Post
    ...

    But how can we Refresh a SPECIFIC bean?
    Very popular question last days.. Why doesn't everyone want to use the forum search...

    Comment


    • #3
      Hi,

      I have not found answer for my question


      I have setup

      1) Mbean stuff in my spring application

      2) mechanism by which reload entire context
      when updating config files (bean xml files)


      Now I need a way by which i can reload a single bean (suppose its with zero dependency)



      I can not find any method for " Reload a single bean when its bean configuration file is changed"

      Comment


      • #4
        If you want to reload a specific bean class on a file change

        XmlWebApplicationContext xmlWebApplicationContext =
        (XmlWebApplicationContext) ContextLoader.getCurrentWebApplicationContext();
        DefaultListableBeanFactory defaultListableBeanFactory =
        (DefaultListableBeanFactory) xmlWebApplicationContext.getBeanFactory();
        BeanDefinition beanDefinition = defaultListableBeanFactory.getBeanDefinition(beanN ame);
        beanDefinition.setBeanClassName(className);
        defaultListableBeanFactory.registerBeanDefinition( beanName, beanDefinition);

        Comment


        • #5
          Hi All,

          I have the following two bean definitions in my application context.

          Suppose, the user can change the following params at runtime:
          1. the cronExpression of the cronTrigger bean
          2. the mail.from of the mailSender bean

          What is the best way to refresh those new property values in the beans already instantiated in Spring ?

          Thanks,
          Ridwaan.

          <!-- Cron Trigger -->
          <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
          <property name="jobDetail" ref="schedulerEmailJob" />
          <property name="cronExpression">
          <value>${cron.batch.trigger.exp}</value>
          </property>
          </bean>

          <!-- Email Sender -->
          <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
          <property name="host" >
          <value>${mailServer.host.ip.address}</value>
          </property>
          <property name="port" >
          <value>${mailServer.host.portNumber}</value>
          </property>
          <property name="username" >
          <value>${mailServer.account.userName}</value>
          </property>
          <property name="password" >
          <value>${mailServer.account.password}</value>
          </property>
          <property name="javaMailProperties">
          <props>
          <prop key="mail.smtp.auth">${mailServer.smtp.auth}</prop>
          <prop key="mail.from">${sender.email}</prop>

          <!-- prop key="mail.smtp.starttls.enable">true</prop-->
          </props>
          </property>
          </bean>

          Comment

          Working...
          X