Marcel Overdijk
Marcel Overdijk

Reputation: 11467

Spring 4 using Groovy setup

Spring 4.0 has improved support for Groovy e.g. using the GroovyBeanDefinitionReader.

What would be setup to to have a full Spring MVC application using Groovy? E.g. using GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext together.

Anyone knows if there is a sample available or some pointers on a blog site?

Upvotes: 2

Views: 2922

Answers (2)

davidiamyou
davidiamyou

Reputation: 390

In your main method, do SpringApplication.run(new Object[]{JavaConfig.class, "beans.groovy"}, args), where JavaConfig contains your configurations in java (like @Configuration, @ComponentScan and etc., I generally find these things are easier using annotations) and beans.groovy just contain your spring beans DSL.

Assuming beans.groovy is on classpth (i.e. under src/main/resources)

Upvotes: 0

englishteeth
englishteeth

Reputation: 228

You might want to check out spring boot, still in milestone release behind Spring 4 but they were really pushing its groovy support at spring eXchange.

Check out the bottom of this spring-boot guide

It's not quite the use of GroovyBeanDefinitionReader and AnnotationConfigWebApplicationContext you asked for, but I can't see why you couldn't do what you are after with the opinionated approach used by spring boot and the standard configuration annotations on groovy classes.

The git hub repository shows a number of annotated groovy examples with ui.groovy for example, showing a configuration class for the WebMvcConfigurerAdapter defining a bean.

Upvotes: 3

Related Questions