Vita Rara: A Life Uncommon

Groovy and Struts 2 Integration


Categories: | | | |

I've done more work on integrating Struts 2 and Groovy. The short news is I'm making progress. I have reloading service beans and actions sort of working. Most of the issues are Spring related (more), but I'm working through those and we'll see what comes of it. With the release of Spring 2.0.3 the AOP issues should be fixed. I haven't actually gotten to testing that yet.

I've spent most of the evening working with getting 2.0.3 working. With the changes in the scripting support it now requires JRuby and BeanShell to be on the classpath. I needed to add the following to my pom.xml file:

<dependency>
    <groupId>org.jruby</groupId>
    <artifactId>jruby-complete</artifactId>
    <version>0.9.8</version>
</dependency>
<dependency>
    <groupId>org.beanshell</groupId>
    <artifactId>bsh</artifactId>
    <version>2.0b4</version>
</dependency>

You'll also need to add AspectJ Weaver to get 2.0.3 AOP support working.

<dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.5.3</version>
</dependency>

Due to the Spring issues I've punted on having Spring instantiate my Groovy actions. I don't like it, but it's a trade off for a greater good, hopefully. I'm making a Struts 2 plugin that will use the GroovyClassLoader to instantiate my Groovy actions, then hand them to Spring for wiring.

I'm not really enamored of this because my integration tests all assume the actions will be instantiated by Spring. I'll need to go back and change that so they instantiate the action, then hand it to Spring for wiring, then invoke methods on them. I also believe that I will need to compile my Groovy actions before integration testing. That's not so bad, but not optimal.

I believe by the end of tomorrow I will have a working plugin, and configuration that will allow the following:

  • Editing of Groovy Actions with dynamic reloading,
  • Ability to wire action dependencies with Spring by name,

Additionally all of the scripting support from Spring is carried over. So, there should be no need to reload the Jetty plugin unless you change a Java interface or class, or need to reload the context.

I envision implementing my action, service beans and DAO's in Groovy. I will leave my JPA entities in Java. Additionally the interfaces for my service beans will remain in Java.

This will save a lot, but not all restarts of the application server. I figure I'll only need to restart when I change a domain entity, or when I add a method to a service interface. All of the time spent implementing that interface, each change, and quick iteration will not require a re-start.