2009-01-20 4 views
12

In Log4j gibt es eine Funktion, mit der das System initialisiert werden kann, um eine Konfiguration vorzunehmen und mit einem Intervall zu überwachen. Dadurch kann das log4j-System seine Eigenschaften immer dann neu laden, wenn die Eigenschaftendatei geändert wird. Hat das Springframework eine Konfigurationsobserver-Einrichtung, in der die Konfiguration neu geladen wird, wenn sie geändert wurde? Die Konfiguration, die neu geladen werden muss, ist nicht die applicationContext.xml von Springs, sondern verschiedene andere Konfigurationsdateien, die mit den Spring-Initialisierungsbeans initialisiert werden. Automatische Neuinitialisierung der Konfiguration im Frühjahr

Antwort

7

Ich fand ein Dienstprogramm, das LogLJ here ähnlich tut. Es ist im Grunde eine Erweiterung von PropertyPlaceholderConfigurer, die Eigenschaften neu lädt, wenn sie sich ändern.

+1

Dies wurde angepasst, um https://github.com/Unicon/springframework-addons/wiki/Auto-Reading-properties-files – Vadzim

+0

@Vadzim Link ist tot! Dies könnte uns im obigen Fall helfen http://projects.spring.io/spring-cloud/spring-cloud.html – pramodc84

+1

@ pramodc84, aktualisierte Links: http://maven-repository.com/artifact/net.unicon.springframework /springframework-addons/0.1, https://github.com/UniconLabs/springframework-addons/blob/master/src/main/java/net/unicon/springframework/addons/properties/ReloadingPropertyPlaceholderConfigurer.java, https: // github .com/knightliao/disconf/blob/master/disconf-client/src/main/java/com/baidu/disconf/client/addons/properties/ReloadingPropertyPlaceholderConfigurer.java – Vadzim

4

AFAIK Spring bietet kein solches Dienstprogramm. Es gibt jedoch ein Drittanbieter-Tool, JRebel, mit dem Sie eine gesamte Webanwendung (einschließlich der Spring-Konfiguration) aktualisieren können, ohne dass ein Neustart des Servers erforderlich ist.

Eine kostenlose Testversion ist verfügbar, und der Kaufpreis ist relativ günstig.

2

Ich wäre besonders vorsichtig mit dem Nachladen von Feder Anwendungskontext.

Was erwarten Sie mit Singleton Bohnen? Wenn ein Objekt einen Verweis auf Singleton Bean hat, sollte es aktualisiert werden?

+0

Ich möchte nicht neu laden spring applicationcontext.xml oder eine der die Frühlingsbohnen sind schon geladen. Ich werde die Lösung ausprobieren, die Phill Sacre gepostet hat. – zkarthik

1

Ich entwickle mit JRebel und ich würde sehr vorsichtig sein zu erwarten, dass es Ihre Konfiguration aktualisieren wird. Funktioniert gut mit Java, nicht mit Spring.

-1

Wenn Sie Kontext hinzufügen mögen, ich habe in der folgenden Weise:

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; 
    } 
} 

Diese Ihr Kontext Provider-Klasse ist. Für Details, können Sie sehen my blog