mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Allow ApplicationContextHelper to support both Lazy and NoAutoStart, where previously it only one at a time could be used.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18844 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,6 +26,8 @@ package org.alfresco.util;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
@@ -82,10 +84,8 @@ public class ApplicationContextHelper
|
|||||||
// The config has changed so close the current context (if any)
|
// The config has changed so close the current context (if any)
|
||||||
closeApplicationContext();
|
closeApplicationContext();
|
||||||
|
|
||||||
if(useLazyLoading) {
|
if(useLazyLoading || noAutoStart) {
|
||||||
instance = new LazyClassPathXmlApplicationContext(configLocations);
|
instance = new VariableFeatureClassPathXmlApplicationContext(configLocations);
|
||||||
} else if(noAutoStart) {
|
|
||||||
instance = new NoAutoStartClassPathXmlApplicationContext(configLocations);
|
|
||||||
} else {
|
} else {
|
||||||
instance = new ClassPathXmlApplicationContext(configLocations);
|
instance = new ClassPathXmlApplicationContext(configLocations);
|
||||||
}
|
}
|
||||||
@@ -119,9 +119,6 @@ public class ApplicationContextHelper
|
|||||||
* to reduce startup times when using a small, cut down context.
|
* to reduce startup times when using a small, cut down context.
|
||||||
*/
|
*/
|
||||||
public static void setUseLazyLoading(boolean lazyLoading) {
|
public static void setUseLazyLoading(boolean lazyLoading) {
|
||||||
if(lazyLoading && noAutoStart) {
|
|
||||||
throw new IllegalStateException("You must choose between LazyLoading and NoAutoStart");
|
|
||||||
}
|
|
||||||
useLazyLoading = lazyLoading;
|
useLazyLoading = lazyLoading;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -142,13 +139,10 @@ public class ApplicationContextHelper
|
|||||||
* you can use this to prevent the auto start.
|
* you can use this to prevent the auto start.
|
||||||
*/
|
*/
|
||||||
public static void setNoAutoStart(boolean noAutoStart) {
|
public static void setNoAutoStart(boolean noAutoStart) {
|
||||||
if(useLazyLoading && noAutoStart) {
|
|
||||||
throw new IllegalStateException("You must choose between LazyLoading and NoAutoStart");
|
|
||||||
}
|
|
||||||
ApplicationContextHelper.noAutoStart = noAutoStart;
|
ApplicationContextHelper.noAutoStart = noAutoStart;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Will subsystems with the autoStart=true property set
|
* Will Subsystems with the autoStart=true property set
|
||||||
* on them be allowed to auto start? The default is to
|
* on them be allowed to auto start? The default is to
|
||||||
* honour the spring configuration and allow them to,
|
* honour the spring configuration and allow them to,
|
||||||
* but they can be prevented if required.
|
* but they can be prevented if required.
|
||||||
@@ -166,4 +160,27 @@ public class ApplicationContextHelper
|
|||||||
}
|
}
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper around {@link ClassPathXmlApplicationContext} which
|
||||||
|
* allows us to enable lazy loading or prevent Subsystem
|
||||||
|
* autostart as requested.
|
||||||
|
*/
|
||||||
|
protected static class VariableFeatureClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
|
||||||
|
protected VariableFeatureClassPathXmlApplicationContext(String[] configLocations) throws BeansException {
|
||||||
|
super(configLocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
|
super.initBeanDefinitionReader(reader);
|
||||||
|
|
||||||
|
if(useLazyLoading) {
|
||||||
|
LazyClassPathXmlApplicationContext.postInitBeanDefinitionReader(reader);
|
||||||
|
}
|
||||||
|
if(noAutoStart) {
|
||||||
|
NoAutoStartClassPathXmlApplicationContext.postInitBeanDefinitionReader(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,7 @@ public class ContextDependencyLister
|
|||||||
{
|
{
|
||||||
public static final String[] DEFAULT_CONFIG_LOCATIONS = new String[] {
|
public static final String[] DEFAULT_CONFIG_LOCATIONS = new String[] {
|
||||||
"classpath:alfresco/application-context.xml"
|
"classpath:alfresco/application-context.xml"
|
||||||
|
// "classpath:alfresco/minimal-context.xml"
|
||||||
// "classpath:test/alfresco/fake-context/application-context.xml"
|
// "classpath:test/alfresco/fake-context/application-context.xml"
|
||||||
};
|
};
|
||||||
private String[] configLocations;
|
private String[] configLocations;
|
||||||
|
@@ -52,6 +52,13 @@ public class LazyClassPathXmlApplicationContext extends
|
|||||||
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
super.initBeanDefinitionReader(reader);
|
super.initBeanDefinitionReader(reader);
|
||||||
|
|
||||||
|
postInitBeanDefinitionReader(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the work of enabling Lazy Init on the xml bean reader
|
||||||
|
*/
|
||||||
|
protected static void postInitBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
reader.setDocumentReaderClass(AlwaysLazyInitBeanDefinitionDocumentReader.class);
|
reader.setDocumentReaderClass(AlwaysLazyInitBeanDefinitionDocumentReader.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,8 +35,8 @@ import org.w3c.dom.Element;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around {@link ClassPathXmlApplicationContext} which
|
* A wrapper around {@link ClassPathXmlApplicationContext} which
|
||||||
* stops abstractPropertyBackedBean based beans from being
|
* stops Alfresco Subsystem (abstractPropertyBackedBean based)
|
||||||
* AutoStarted by tweaking their property definitions.
|
* beans from being AutoStarted by tweaking their property definitions.
|
||||||
* You shouldn't do this in production, but it can be handy with
|
* You shouldn't do this in production, but it can be handy with
|
||||||
* unit tests, as it allows a quicker startup by preventing
|
* unit tests, as it allows a quicker startup by preventing
|
||||||
* subsystems from starting up
|
* subsystems from starting up
|
||||||
@@ -54,6 +54,15 @@ public class NoAutoStartClassPathXmlApplicationContext extends
|
|||||||
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
super.initBeanDefinitionReader(reader);
|
super.initBeanDefinitionReader(reader);
|
||||||
|
|
||||||
|
postInitBeanDefinitionReader(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the work of disabling the autostart of the
|
||||||
|
* Subsystem (abstractPropertyBackedBean) beans
|
||||||
|
* on the xml bean reader
|
||||||
|
*/
|
||||||
|
protected static void postInitBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
reader.setDocumentReaderClass(NoAutoStartBeanDefinitionDocumentReader.class);
|
reader.setDocumentReaderClass(NoAutoStartBeanDefinitionDocumentReader.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +86,8 @@ public class NoAutoStartClassPathXmlApplicationContext extends
|
|||||||
String propertyName = ele.getAttribute("name");
|
String propertyName = ele.getAttribute("name");
|
||||||
if("autoStart".equals(propertyName)) {
|
if("autoStart".equals(propertyName)) {
|
||||||
if("abstractPropertyBackedBean".equals(bd.getParentName())) {
|
if("abstractPropertyBackedBean".equals(bd.getParentName())) {
|
||||||
System.out.println("Preventing the autostart of " + bd.getBeanClassName());
|
String id = ele.getParentNode().getAttributes().getNamedItem("id").getTextContent();
|
||||||
|
System.out.println("Preventing the autostart of Subsystem " + id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user