@@ -750,7 +750,8 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
750
750
public static AbstractRefreshableApplicationContext refreshApplicationContext (AbstractRefreshableApplicationContext ctx ,
751
751
boolean isOpenmrsStartup , Module startedModule ) {
752
752
//notify all started modules that we are about to refresh the context
753
- for (Module module : ModuleFactory .getStartedModules ()) {
753
+ Set <Module > startedModules = new HashSet <Module >(ModuleFactory .getStartedModules ());
754
+ for (Module module : startedModules ) {
754
755
try {
755
756
if (module .getModuleActivator () != null )
756
757
module .getModuleActivator ().willRefreshContext ();
@@ -791,16 +792,19 @@ public static AbstractRefreshableApplicationContext refreshApplicationContext(Ab
791
792
792
793
// reload the advice points that were lost when refreshing Spring
793
794
if (log .isDebugEnabled ())
794
- log .debug ("Reloading advice for all started modules: " + ModuleFactory . getStartedModules () .size ());
795
+ log .debug ("Reloading advice for all started modules: " + startedModules .size ());
795
796
796
797
try {
797
798
//The call backs in this block may need lazy loading of objects
798
799
//which will fail because we use an OpenSessionInViewFilter whose opened session
799
800
//was closed when the application context was refreshed as above.
800
801
//So we need to open another session now. TRUNK-3739
801
802
Context .openSessionWithCurrentUser ();
802
-
803
- for (Module module : ModuleFactory .getStartedModules ()) {
803
+ for (Module module : startedModules ) {
804
+ if (!module .isStarted ()) {
805
+ continue ;
806
+ }
807
+
804
808
ModuleFactory .loadAdvice (module );
805
809
try {
806
810
ModuleFactory .passDaemonToken (module );
@@ -817,7 +821,7 @@ else if (!isOpenmrsStartup && module.equals(startedModule))
817
821
}
818
822
catch (Exception e ) {
819
823
log .warn ("Unable to invoke started() method on the module's activator" , e );
820
- ModuleFactory .stopModule (module );
824
+ ModuleFactory .stopModule (module , true , true );
821
825
}
822
826
}
823
827
0 commit comments