Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide first class support for Groovy context loading in tests [SPR-11631] #16254

spring-projects-issues opened this issue Mar 30, 2014 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Mar 30, 2014

Abhijit Sarkar opened SPR-11631 and commented

There is no support for reading Groovy config files in tests without writing a custom ContextLoader. The default @ContextConfiguration tries to interpret Groovy files as XMLs.
I have created a bare bone ContextLoader for supporting Groovy config. I'm interested in submitting a pull request but see that the asks that I create a JIRA first.

 * Class-level annotation that is used to determine how to load and configure an
 * ApplicationContext for integration tests. Similar to the standard
 * {@link org.springframework.test.context.ContextConfiguration} but uses
 * {@link GenericGroovyContextLoader}.
 * @author Abhijit Sarkar
 * @see GenericGroovyContextLoader
@ContextConfiguration(loader = GenericGroovyContextLoader.class)
public @interface GroovyContextConfiguration {

     * @see ContextConfiguration#locations()
    String[] locations() default {};

     * @see ContextConfiguration#classes()
    Class<?>[] classes() default {};

     * @see ContextConfiguration#initializers()
    Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers() default {};

     * @see ContextConfiguration#inheritLocations()
    boolean inheritLocations() default true;

     * @see ContextConfiguration#inheritInitializers()
    boolean inheritInitializers() default true;

     * @see ContextConfiguration#name()
    String name() default "";


public class GenericGroovyContextLoader extends AbstractGenericContextLoader {
    protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) {
        final GroovyBeanDefinitionReader reader = new GroovyBeanDefinitionReader(context);

        final Binding binding = getBinding(reader);


        return reader;

    protected Binding getBinding(final GroovyBeanDefinitionReader reader) {
        return new Binding();

    protected String getResourceSuffix() {
        return ".groovy";


@GroovyContextConfiguration(locations = ['classpath:service-config.groovy', 'classpath:integ-test-config.groovy',
abstract class AbstractSpringIntegrationTest {

Affects: 4.0.3

Issue Links:

  • #15858 Support Groovy scripts for bean definitions in the TestContext framework ("duplicates")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants