RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Stereotype Annotations Cut Down XML Configuration in Spring : Page 5

Spring stereotype annotations can greatly reduce the amount of XML configuration required to build and maintain a Spring application.


Annotation Pros and Cons

Stereotype annotations can greatly reduce Spring XML configuration. XML documents are not the easiest to read or maintain, and XML itself is very verbose. Annotations are not only a simpler alternative, but they also are attached to the program artifacts they describe, giving the metadata information relevance that is not always there or clear when viewed in an XML file. In Spring, this sentiment is expressed by the "don't repeat yourself" (DRY) principle. Annotations provide one unambiguous and authoritative representation for any piece of knowledge.

However, because annotations are part of the source code, they are compiled right into the class files. This has both advantages and disadvantages. On one hand, an incorrect or stale XML file cannot be accidentally used to configure the application. On the other hand, annotations require the code to be recompiled if a configuration change is necessary; some request mapping was moved to XML configuration files in some MVC environments precisely to avoid this. An XML configuration file allows for application changes without the source.

Figure 3. Application Changes Between Dev and Production Environments: Critics of annotations claim XML configuration allows changes between development and production environments more easily.

Consider what changes as you move your application from dev to test to stage to production platforms (see Figure 3). Do these changes also impact cross-cutting concerns?

In any case, Spring Stereotype annotations can greatly reduce the amount of XML configuration required to build and maintain a Spring application. In some cases, they allow the application components to be more loosely coupled to Spring or other APIs. Ceratainly, given comments by Rod Johnson and others, the Spring communicaty can look forward to annotations playing an even bigger part of Spring applications in the future.

Jim White is an instructor with Intertech Training. He is also co-author of Java 2 Micro Edition, (Manning).
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date