From 32e851617e5fbc2864127017444ab60f1fe2a482 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 17 Aug 2020 15:37:51 +0200 Subject: [PATCH 1/3] Fix Javadoc formatting in GenericGroovyXmlContextLoader --- .../test/context/support/GenericGroovyXmlContextLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java index 9a46a070ea4..86dc00da948 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java @@ -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"); * 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. */ @Override From a83529c844f9468223c634bac7ba22b4587e0925 Mon Sep 17 00:00:00 2001 From: Maciej Miklas Date: Mon, 17 Aug 2020 14:10:49 +0200 Subject: [PATCH 2/3] Introduce createContext() factory method in AbstractGenericContextLoader Prior to this commit it was possible to configure the DefaultListableBeanFactory used by the GenericApplicationContext created by AbstractGenericContextLoader, but it was not possible to completely replace the bean factory. This commit introduces a new createContext() factory method in AbstractGenericContextLoader which indirectly allows subclasses to supply a custom DefaultListableBeanFactory implementation to the GenericApplicationContext. Closes gh-25600 --- .../support/AbstractGenericContextLoader.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index 8cefc456fb0..5729a02c580 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -112,7 +112,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader validateMergedContextConfiguration(mergedConfig); - GenericApplicationContext context = new GenericApplicationContext(); + GenericApplicationContext context = createContext(); ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { @@ -130,6 +130,15 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader return context; } + /** + * Creates instance of application context used by this {@code ContextLoader} + * + * @return new Instance of application context + */ + protected GenericApplicationContext createContext() { + return new GenericApplicationContext(); + } + /** * Validate the supplied {@link MergedContextConfiguration} with respect to * what this context loader supports. @@ -184,7 +193,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader logger.debug(String.format("Loading ApplicationContext for locations [%s].", StringUtils.arrayToCommaDelimitedString(locations))); } - GenericApplicationContext context = new GenericApplicationContext(); + GenericApplicationContext context = createContext(); prepareContext(context); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); From d939016a091b8f0c6520a2f6f08c576f966bfa32 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 17 Aug 2020 15:53:45 +0200 Subject: [PATCH 3/3] Polish contribution See gh-25600 --- .../support/AbstractGenericContextLoader.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index 5729a02c580..b2ea37b9fec 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -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"); * you may not use this file except in compliance with the License. @@ -70,7 +70,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *
    *
  • Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.
  • - *
  • Creates a {@link GenericApplicationContext} instance.
  • + *
  • Calls {@link #createContext()} to create a {@link GenericApplicationContext} + * instance.
  • *
  • If the supplied {@code MergedContextConfiguration} references a * {@linkplain MergedContextConfiguration#getParent() parent configuration}, * the corresponding {@link MergedContextConfiguration#getParentApplicationContext() @@ -130,15 +131,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader return context; } - /** - * Creates instance of application context used by this {@code ContextLoader} - * - * @return new Instance of application context - */ - protected GenericApplicationContext createContext() { - return new GenericApplicationContext(); - } - /** * Validate the supplied {@link MergedContextConfiguration} with respect to * what this context loader supports. @@ -159,7 +151,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *

    Implementation details: * *

      - *
    • Creates a {@link GenericApplicationContext} instance.
    • + *
    • Calls {@link #createContext()} to create a {@link GenericApplicationContext} + * instance.
    • *
    • Calls {@link #prepareContext(GenericApplicationContext)} to allow for customizing the context * before bean definitions are loaded.
    • *
    • Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the @@ -204,6 +197,22 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader return context; } + /** + * Factory method for creating the {@link GenericApplicationContext} used by + * this {@code ContextLoader}. + * + *

      The default implementation creates a {@code GenericApplicationContext} + * using the default constructor. This method may be overridden in subclasses + * — 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}. * Called before bean definitions are read.