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

StackOverflow https://stackoverflow.com/questions/3816077

  •  26-09-2019
  •  | 
  •  

Question

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?

Was it helpful?

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

OTHER TIPS

Have a look at the Grails Spring BeanBuilder, that provides a "groovy" way for the definition and configuration of Spring beans: http://www.grails.org/Spring+Bean+Builder

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top