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 dedicated ApplicationContext implementations for use with (JavaConfig) @Configuration classes [SPR-5682] #10353

Closed
spring-projects-issues opened this issue Apr 17, 2009 · 8 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 17, 2009

Chris Beams opened SPR-5682 and commented

The JavaConfig project provided [JavaConfigApplicationContext](http://static.springframework.org/spring-javaconfig/docs/1.0.0.M4/javadoc-api/org/springframework/config/java/context/JavaConfigApplicationContext.html) and [JavaConfigWebApplicationContext](http://static.springframework.org/spring-javaconfig/docs/1.0.0.M4/javadoc-api/org/springframework/config/java/context/JavaConfigWebApplicationContext.html) to allow for eliminating XML entirely. (See also: usage).

Similar implementations could be provided in Spring Core, though naming would probably change to ConfigurationClassApplicationContext and ConfigurationClassWebApplicationContext, respectively.

There are a number of issues to consider and work out before providing this support, but this issue can serve as a way to track community interest.


Sub-tasks:

Issue Links:

Referenced from: commits cbadf35, fd8935b, a48234c, 772a74a

12 votes, 13 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Current not-too-bad option, assuming annotated classes in "mypackage":

GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.scan("mypackage");
context.refresh();

ConfigurationClassPostProcessor gets automated automatically... So this is actually about general classpath-scanning ApplicationContext convenience!

In the web case (as of 3.0 M3):

GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext);
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.scan("mypackage");
context.refresh();

The only thing we're missing is a ClassPathXmlApplicationContext / XmlWebApplicationContext equivalent. I'm not sure whether we should turn the Generic(Web)ApplicationContext model into more of a first-class feature, or rather build ClassPathScanningApplicationContext-style convenience classes...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Craig Walls commented

The option that Juergen offers is better than nothing, but it's not a one-for-one swap with what is available for the XML configuration option. The XML-haters may not be appeased if they have to do any more (even if it's a little more) than what you have to do for the XML configuration.

I'm in favor of including JavaConfigApplicationContext and JavaConfigWebApplicationContext in Spring 3. Just my $0.02.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Assigning this to you, Chris - as per our discussion today, with the goal being inclusion of ConfigurationClassApplicationContext and co in Spring 3.0 RC1.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Gabriel Axel commented

Will it include the annotations-related features that were added to JavaConfig M4 (@AnnotationDrivenTx, @AnnotationDrivenTx, etc) ? It will be be very helpful to have them in the Spring core.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

@Gabriel - not exactly, but equivalents will be provided; and if not immediately, within the Spring 3.1 timeframe. As for @AnnotationDrivenConfig, it is unnecessary as this behavior will be enabled by default when bootstrapping via the forthcoming ConfigurationClass[Web]ApplicationContext. @AnnotationDrivenTx will probably take a different shape in the short term. It is a problem to commit to these annotations, because the implication is that we will provide annotation-based equivalents for all the functionality currently provided by the various XML namespaces and their respective elements. For example, we would need to provide @MBeanExport, @OsgiService, @OsgiReference, etc, etc. This represents not only an ugly and ongoing duplication of efforts, but is also non-idiomatic Java. Simply said, using all these annotations ends up being a little too weird.

The general goal at this time is to provide programmatic access to the same APIs that underlie the XML namespaces themselves (search around for NamespaceHandler implementations within Spring Core). This requires a fair bit of refactoring of the NamespaceHandler API, and thus will not happen until Spring 3.1.

In the meantime, along with the new ConfigurationClassApplicationContext implementations, we will also commit @ImportXml, which will provide easy access to any XML features not (yet) directly supported by the @Configuration model (e.g.: <tx:annotation-driven/>).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Just added org.springframework.web.context.support.ConfigurationClassWebApplicationContext. A number of folks are watching this issue; any road tests and feedback would be most appreciated.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

FYI, I'm in the process of reworking CC(W)AC into general AnnotationConfigApplicationContext and AnnotationConfigWebApplicationContext implementations: supporting @Configuration classes but also plain @Components, with options for explicit registration of classes as well as for classpath scanning. Seems to work fine for @Configuration purposes still... and provides great convenience for the @Component model and the JSR-330 model as well, all of which are tied up nicely in Spring 3.0 now.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants