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

Seamless support for Groovy bean definitions mixed with XML bean definitions [SPR-11924] #16542

Closed
spring-projects-issues opened this issue Jun 27, 2014 · 2 comments
Assignees
Labels
in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 27, 2014

David Turanski opened SPR-11924 and commented

Currently, Groovy beans are only loaded when creating a GenericGroovyApplicationContext. An improvement would be GenericResourceApplicationContext, or something similar that looks at the file extension to use GroovyBeanDefinitionReader or XMLBeanDefinitionReader, respectively. I did something similar for XD here, but I think this should be in core Spring:

https://github.com/spring-projects/spring-xd/blob/master/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/container/initializer/AbstractResourceBeanDefinitionProvider.java

Also, @ImportResource("config.groovy") should work.


Referenced from: commits 37ba1b9

@spring-projects-issues
Copy link
Collaborator Author

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

Juergen Hoeller commented

Hmm, a GenericResourceApplicationContext would be a bit of a god class in concept and would only work if Groovy was on the classpath...

Instead, it seems more natural to add that capability to GroovyBeanDefinitionReader itself which has a switch between ".xml" and ".groovy" in its importBeans functionality already: I've extended this to its loadBeanDefinitions variants, being able to redirect XML files to its internal XmlBeanDefinitionReader (which it always had anyway) as well.

This also translates through to GenericGroovyApplicationContext, being a groovyfied context implementation which now also provides seamless XML support with any of its load methods - and can therefore serve as a generic resource entry point, as long as you have Groovy on the classpath.

As for @ImportResource("config.groovy"), that would currently require an extra reader=GroovyBeanDefinitionReader.class attribute. We can try to smartly pick GroovyBeanDefinitionReader when Groovy is on the classpath there, since it can seamlessly handle XML files now anyway.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

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

Juergen Hoeller commented

GroovyBeanDefinitionReader and Groovy ApplicationContexts redirect ".xml" files to XmlBeanDefinitionReader now, similar to what they've been doing for importBeans directives already.

Analogously, @ImportResource for configuration classes redirects ".groovy" to GroovyBeanDefinitionReader now. Unknown suffixes will still be processed as XML content for backwards compatibility.

David, please give this a try against an upcoming 4.1 snapshot and let me know whether it's doing what you expect it to do by default now...

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants