dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Sep 25, 2009

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Define and Execute a Groovy Bean Inside a Spring Application Context

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:


 <beans xmlns="http://www.springframework.org/schema/beans"  
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     xmlns:lang="http://www.springframework.org/schema/lang"  
     xsi:schemaLocation="http://www.springframework.org/schema/beans  
         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
         http://www.springframework.org/schema/lang  
         http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">

 <lang:groovy id="helloWorldService"  
              script-source="classpath:com/springandgroovy/HelloWorldServiceImpl.groovy">  
              <lang:property name="name" value="meera"/>  
 </lang:groovy>

Finally, here's an execution example:

HelloWorldService service = (HelloWorldService) context.getBean(
   "helloWorldService");  
 
System.out.println(service.sayHello());
Santiago Urrizola
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
By using this site, you agree to the Privacy Policy
Thanks for your registration, follow us on our social networks to keep up-to-date