Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

Alternate Spring-Groovy-Integration Add comment to Wiki View in Wiki Edit Wiki page Printable Version

Abstract

Alternate way to integrate Groovy in a Java-Application using Spring, without the usage of <lang:groovy/>-Tags.

Advantages

  • Works with Spring-AOP
  • You can use other Groovy-Classes e.g. internal datatypes, in your Beans without the need to inject them.

Example

Java Code that's create the App-Context
...
private GenericApplicationContext createAppContext(String path) {
	GenericApplicationContext ctx = new GenericApplicationContext();

        GroovyClassLoader defaultClassLoader = new GroovyClassLoader(this.getClass().getClassLoader());

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
	reader.setBeanClassLoader(defaultClassLoader);
	reader.loadBeanDefinitions(path);
	ctx.refresh();
	return ctx;
}
...
Sample beans.xml
<bean id="tm" class="ticketing.bo.impl.TicketManagerImpl"/>
ticketing/bo/impl/TicketAssemblerImpl.groovy
class TicketAssemblerImpl implements IBaseAssembler {
 ...
}

Hopefully that is helpful...