Merge branch '5.2.x'

This commit is contained in:
Sam Brannen 2020-08-17 16:01:32 +02:00
commit 50b20c2bb7
2 changed files with 25 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -70,7 +70,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
* <ul> * <ul>
* <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)} * <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)}
* to allow subclasses to validate the supplied configuration before proceeding.</li> * to allow subclasses to validate the supplied configuration before proceeding.</li>
* <li>Creates a {@link GenericApplicationContext} instance.</li> * <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
* instance.</li>
* <li>If the supplied {@code MergedContextConfiguration} references a * <li>If the supplied {@code MergedContextConfiguration} references a
* {@linkplain MergedContextConfiguration#getParent() parent configuration}, * {@linkplain MergedContextConfiguration#getParent() parent configuration},
* the corresponding {@link MergedContextConfiguration#getParentApplicationContext() * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
@ -112,7 +113,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
validateMergedContextConfiguration(mergedConfig); validateMergedContextConfiguration(mergedConfig);
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = createContext();
ApplicationContext parent = mergedConfig.getParentApplicationContext(); ApplicationContext parent = mergedConfig.getParentApplicationContext();
if (parent != null) { if (parent != null) {
@ -150,7 +151,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
* <p>Implementation details: * <p>Implementation details:
* *
* <ul> * <ul>
* <li>Creates a {@link GenericApplicationContext} instance.</li> * <li>Calls {@link #createContext()} to create a {@link GenericApplicationContext}
* instance.</li>
* <li>Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context * <li>Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context
* before bean definitions are loaded.</li> * before bean definitions are loaded.</li>
* <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the * <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the
@ -184,7 +186,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
logger.debug(String.format("Loading ApplicationContext for locations [%s].", logger.debug(String.format("Loading ApplicationContext for locations [%s].",
StringUtils.arrayToCommaDelimitedString(locations))); StringUtils.arrayToCommaDelimitedString(locations)));
} }
GenericApplicationContext context = new GenericApplicationContext(); GenericApplicationContext context = createContext();
prepareContext(context); prepareContext(context);
customizeBeanFactory(context.getDefaultListableBeanFactory()); customizeBeanFactory(context.getDefaultListableBeanFactory());
createBeanDefinitionReader(context).loadBeanDefinitions(locations); createBeanDefinitionReader(context).loadBeanDefinitions(locations);
@ -195,6 +197,22 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader
return context; return context;
} }
/**
* Factory method for creating the {@link GenericApplicationContext} used by
* this {@code ContextLoader}.
*
* <p>The default implementation creates a {@code GenericApplicationContext}
* using the default constructor. This method may be overridden in subclasses
* &mdash; for example, to create a {@code GenericApplicationContext} with
* a custom {@link DefaultListableBeanFactory} implementation.
*
* @return a newly instantiated {@code GenericApplicationContext}
* @since 5.2.9
*/
protected GenericApplicationContext createContext() {
return new GenericApplicationContext();
}
/** /**
* Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}. * Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}.
* Called <i>before</i> bean definitions are read. * Called <i>before</i> bean definitions are read.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ public class GenericGroovyXmlContextLoader extends GenericXmlContextLoader {
} }
/** /**
* Returns {@code "-context.xml" and "Context.groovy"} in order to * Returns {@code "-context.xml"} and {@code "Context.groovy"} in order to
* support detection of a default XML config file or Groovy script. * support detection of a default XML config file or Groovy script.
*/ */
@Override @Override