A quick example should suffice for defining and executing a Groovy Bean inside a Spring application context. Here’s a short Java interface:
package com.springandgroovy; public interface HelloWorldService { String sayHello(); }
And here’s the Groovy implementation:
import com.springandgroovy.HelloWorldService; class HelloWorldServiceImpl implements HelloWorldService { String name String sayHello() { "Hello $name. Welcome to Scripting in Groovy." } }
The Spring application context is:
Finally, here’s an execution example:
HelloWorldService service = (HelloWorldService) context.getBean( "helloWorldService"); System.out.println(service.sayHello());