Whilst working with Spring is great, Java was just becoming too verbose, so I decided to make an effort to integrate Groovy.
Turns out its pretty easy..
First add the following dependency to your Maven pom.xml:
<!-- Groovy -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
</dependency>
Next modify the maven compiler plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>false</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.6.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.6-01</version>
</dependency>
</dependencies>
</plugin>
At that's basically it. If you are working on a Spring MVC project like I am, you can now create .groovy files in src/main/java or src/main/groovy. In addition you can also annotate them with @Service etc and @Autowire them into other Java or Groovy classes.
One problem I did have was autowiring a groovy bean that was annotated with @Transactional into another. It turns out the probject was because the class did not have an interface and this causes proxy problems for Spring. The following change to the bean solved the problem:
@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class UserNotificationsScheduled {
..
}
RSS Feed