Skip to content

Provide dedicated ApplicationContext implementations for use with (JavaConfig) @Configuration classes [SPR-5682] #10353

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on May 4, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. spring-projects-issues commented on Jun 30, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on Sep 2, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  4. spring-projects-issues commented on Sep 28, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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.

  5. spring-projects-issues commented on Sep 28, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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/>).

  6. spring-projects-issues commented on Oct 4, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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.

  7. spring-projects-issues commented on Oct 21, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  8. added
    type: enhancement
    in: core
    has: votes-jira
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has: votes-jirain: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions