Results 1 to 7 of 7

Thread: Reloading application contexts in a Web application

  1. #1
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Roeselare, Belgium
    Posts
    16

    Default

    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());

  3. #3

    Default

    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. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote 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

  5. #5

    Default

    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!

  6. #6
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    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

  7. #7
    Join Date
    Oct 2010
    Posts
    2

    Post 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>

Similar Threads

  1. Replies: 5
    Last Post: Oct 8th, 2006, 12:39 PM
  2. Questioning the core component
    By Martin Kersten in forum Swing
    Replies: 6
    Last Post: Feb 21st, 2005, 03:45 AM
  3. Replies: 0
    Last Post: Jan 25th, 2005, 05:10 PM
  4. Slow & heavy web application reloading
    By ImanRahmati in forum Web
    Replies: 1
    Last Post: Nov 4th, 2004, 01:51 PM
  5. Newbie question - Application contexts
    By rlebel in forum Container
    Replies: 2
    Last Post: Sep 28th, 2004, 09:25 AM

Posting Permissions

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