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

  • Reloading application contexts in a Web application


    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?


  • #2
    You can use

    You can get the applicationContext by implementing ApplicationContextAware or with something like

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


    • #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 !


      • #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.



        • #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

          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,
          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...



          • #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?



            • #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 ?


              <!-- Cron Trigger -->
              <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
              <property name="jobDetail" ref="schedulerEmailJob" />
              <property name="cronExpression">

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

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