Search code examples
springdslmaven-3polyglot

Maven 3 has a new DSL formats for its POM. Is there a similar sort of format for Spring applicationcontext.xml files?


In Maven 3 there are new DSL replacements for the POMs. See: http://polyglot.sonatype.org/groovy.html for the wonderfully terse syntax.

Is there something similar that can be used for Spring applicationcontext.xml files?


Solution

  • In Spring 3 you may use Java-based container configuration, see 3.11 Java-based container configuration. It also plays well with autodetection of components. To use these features instead of applicationContext.xml, add the following to web.xml:

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            ... package and class names to use for configuration ...
        </param-value>
    </context-param>
    

    You may also configure DispatcherServlet in the same way - with <init-param> instead of <context-param>.