25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 18 ■ <strong>Spring</strong> and Groovy<br />

//Equivalent to:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

It is necessary to add a defined namespace, and if a bean uses some attributes, then the name must be after the<br />

class definition, followed by a colon and the value; if the attribute contains a hyphen, it must be enclosed between<br />

single quotes. The namespace must be first on the line of the beans, separated by a space and the URL between<br />

double quotes and after a colon.<br />

xmlns name:"URL"<br />

beanId ( class, attribute : value [, attibute : value, 'attribute-xy': value ])<br />

Example:<br />

beans {<br />

}<br />

xmlns rabbit:"http://www.springframework.org/schema/rabbit"<br />

rabbit.'connection-factory'(id:"rabbitConnectionFactory", host:"localhost")<br />

//Equivalent to:<br />

<br />

<br />

<br />

As you can see, you can simplify your bean definitions by using the <strong>Spring</strong> DSL and you can remove all the<br />

verbosity from the XML. Of course, you can still use the XML together with this new <strong>Spring</strong> DSL. Imagine that you<br />

have a library already that contains an XML configuration and you want it to be part of the <strong>Spring</strong> DSL. How can you<br />

include it? Very easily; just use the importBeans and that’s it. See Listing 18-8.<br />

261

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!