Results 1 to 2 of 2

Thread: Problems with refreshing a context

  1. #1

    Default Problems with refreshing a context

    I am using Spring 2.0 on JDK6.

    What problems could be caused by refreshing a context
    in a bean that was created by the context? That is,
    bean X was created by a web application context C
    and bean X chooses to do the following:

    Code:
      class X implements ApplicationContextAware {
          private ConfigurableApplicationContext ctx;
          public void setApplicationContext(final ApplicationContext ctx) {
              this.ctx = (ConfigurableApplicationContext) ctx;
          }
          //...
          public void refresh() {
             if (ctx != null) {
               ctx.refresh();
               getLogger().log("Reloaded the application...");
             }
      }
    If the refresh method of X is invoked, what would be the state of the bean
    after ctx.refresh() is invoked? Let's assume that there are no
    requests being serviced.

    Is this is a correct way of refreshing the context?

    Regards,

    /U

  2. #2
    Join Date
    Aug 2006
    Location
    Melbourne, Victoria, Australia
    Posts
    55

    Exclamation

    If this bean X is a singleton managed by its BeanFactory it will be destroyed (its destroy() or custom method will be called) and it will be removed from the list of context managed beans. During refresh another bean X will be created.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •