Announcement Announcement Module
Collapse
No announcement yet.
Reloading application contexts in a Web application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reloading application contexts in a Web application

    Hello,

    Is there a simple way to reload the application contexts used by a Spring MVC based Web application without restarting the servlet engine? Something like a simple HTTP request to a special development-only servlet that reloads the entire application context hierarchy rooted at the application context found in the ServletContext.

    As far as I can see this does not exist. Maybe it is a planned feature? Or are there any issues that prevent something like this from being implemented?

    Erwin

  • #2
    You can use

    Code:
    ((ConfigurableApplicationContext)applicationContext).refresh();
    You can get the applicationContext by implementing ApplicationContextAware or with something like

    Code:
    ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext)WebApplicationContextUtils.getWebApplicationContext(getServlet().getServletContext());

    Comment


    • #3
      How can I do that in Standalone application.

      If it's an web application

      WebApplicationContextUtils.getWebApplicationContex t(getServlet().getServletContext());

      this works !

      In standalone application, how can I achieve this ?

      Thanks !

      Comment


      • #4
        Originally posted by udaygarikapati View Post
        In standalone application, how can I achieve this ?
        Hmm, don't you know yourself where you store the application context and how to access it? Nobody can't help you with YOUR application.

        Joerg

        Comment


        • #5
          May be I have posted question wrongly !

          I have written a util class SpringUtil, in that I have loaded my spring config file
          at application starting time

          private static ClassPathXmlApplicationContext appContext = null;

          public static ClassPathXmlApplicationContext getSpringContext() {

          if (appContext == null) {
          log.debug("Re-Loading Spring applicationContext");
          appContext = new ClassPathXmlApplicationContext(
          StringUtils.commaDelimitedListToStringArray( PropertyUtils.getProperty("spring_context_files")
          ));
          log.debug("Successfully Re-Loaded Spring pplicationContext
          : "+appContext);
          }

          return appContext;
          }
          Later if I want to load my bean, I will do like this

          SpringUtil.getSpringContext().getBean("myDAO");
          Now what I need is, at some other location in the code, I want to know is
          there any existing spring context existing or not (not thru SpringUtil class) ?
          This we can do in an webapplication environment like I posted above.

          If it exists , I can take the context and load some more beans from another
          appContext.xml file

          new ClassPathXmlApplicationContext(String[] a,
          ApplicationContext)
          or some other way !

          Is there a way to check for already loaded spring context ? or else can I
          export loaded spring context to the JVM or such like...

          Thanks!

          Comment


          • #6
            No, in a Spring standalone application you are responsible for managing your application contexts. Nobody else is aware of them. If SpringUtils holds your application context why don't you want to use it for checking for the existence of an application context as well?

            Joerg

            Comment


            • #7
              changing bean property values at runtime

              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