Automatic configuration reinitialization in Spring

前端 未结 5 621
谎友^
谎友^ 2021-01-04 11:18

In Log4j, there is a feature wherein the system can be initialized to do a configure and watch with an interval. This allows for the log4j system to reload its properties wh

相关标签:
5条回答
  • 2021-01-04 11:28

    I would be extra cautious with reloading spring application context.

    What do you expect to happen with singleton beans? If an object has a reference to singleton bean, should it be updated?

    0 讨论(0)
  • 2021-01-04 11:41

    If you would like to add context, I have done that in the following way :

    public class ApplicationContextUtil
    {
       static String[] configFiles = {"applicationContextParent.xml"};
    
       private static ApplicationContext context = null;
    
       static
       {
           context = new ClassPathXmlApplicationContext ( configFiles );
       }
    
       public static void addContext( String[] newConfigFiles )
       {
           // add the new context to the previous context
           ApplicationContext newContext =  new ClassPathXmlApplicationContext ( newConfigFiles, context );
           context = newContext;
       }   
       public static ApplicationContext getApplicationContext ()
       {
           // return the context
           return context;
       }
    }
    

    This is your context provider class. For details, you can look at my blog

    0 讨论(0)
  • 2021-01-04 11:43

    AFAIK Spring does not provide such a utility. However there is a 3rd party tool, JRebel that enables you to update an entire web application (including the Spring configuration) without requiring a server restart.

    A free trial is available, and the purchase price is fairly inexpensive.

    0 讨论(0)
  • 2021-01-04 11:44

    I develop using JRebel and I would be very wary of expecting it to refresh your configuration. Works fine with Java, not with Spring though.

    0 讨论(0)
  • 2021-01-04 11:45

    I found a utility that does something similar to Log4J here. It's basically an extension to PropertyPlaceholderConfigurer that reloads properties when they change.

    0 讨论(0)
提交回复
热议问题