user1900662
user1900662

Reputation: 299

Why are annotations preferred over deployment descriptors in Java EE?

With deployment descriptors I can easily configure the beans and other servlet information during deployment without the need to open the code and compile it again.

Then why annotations replaced the deployment descriptors, annotations are followed in spring, JSF 2.0 and hibernate too.

Can any one tell me the main advantages of annotations over deployment descriptors and other config files like( beans.xml, spring-config.xml, struts.xml)?

Upvotes: 3

Views: 2090

Answers (1)

Grzegorz Grzybek
Grzegorz Grzybek

Reputation: 6237

First, there's a trend to replace a kind of dual language programming (Java + XML) with only one (Java).

And it is sometimes true - it's easy to analyze and prototype an application, when everything (data, methods and metadata/annotations) are in one place.

But there's also hidden truth. XML has it's use and in Spring there's a kind of XML DSL - dedicated XML tags/attributes to configure particular aspects of application (Security, MVC, Transaction configuration, AOP). And using this it's much easier to write and (what's more important) read and maintain such configuration.

And one, sometimes forgotten aspect. With XML you can have two objects of the same class configured differently. With annotations, you put them on the class, so every object of such class is generally the same.

Upvotes: 5

Related Questions