Webcam Chat Satellite Internet QuickBooks Advice international calling cards international phone cards
Submit Your Blog Feedback Request Article Print Email

Integrating Spring and Groovy

Author : Christy
Topic : spring groovy 
Pages :

3) Inlining Groovy objects

3.1) Introduction

It is also possible to inline Groovy code directly in the Spring's configuration file rather than having the code in a separate .groovy file. This will be useful at times when the size of the Groovy code is comparatively smaller.

3.2) Spring's Configuration file

inline.xml


<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

    <lang:groovy id="person">
        <lang:inline-script>

        package javabeat.net.articles.spring.groovy.integration.inline

        public class Person
        {
            String name
            int age
            double salary

            public void toString(){
                println (name + "::" + age + "::" + salary);
            }
        }            

        </lang:inline-script>

        <lang:property name="name" value="Nicolas" />
        <lang:property name="age" value="43" />
        <lang:property name="salary" value="56789" />

    </lang:groovy>

</beans>

In the above configuration file, the new Groovy type called Person is created within a well-defined package. Note that the Groovy code should be embedded with the tags lang:inline. It is also possible to define an object of type Person as well as to pass parameters to the defined object with the help of the 'property' tags.

Submit Your Blog Feedback Request Article Print Email

Java / J2EE Tutorials

Spring Framework

Hibernate Framework

JSF Framework

Struts Framework

Java Server Pages(JSP)

Servlets

Java / J2EE Design Patterns

SCJP

SCEA


Favorites
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Website (2004-2009), India
javabeat | about us | useful resources
Copyright (2004 - 2009), JavaBeat