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 having to open the code and compile it again.

Then why annotations replaced deployment descriptors, annotations follow in spring, JSF 2.0 and hibernate.

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

+3


source to share


1 answer


Firstly, there is a tendency to replace the kind of dual core programming (Java + XML) with just one (Java).

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



But there is also a hidden truth. XML uses it, and in Spring there are certain XML DSL XML tags / attributes for customizing certain aspects of the application (security, MVC, transaction configuration, AOP). And using that makes it much easier to write and (more importantly) to read and maintain such a configuration.

And one, sometimes forgotten aspect. With XML, you can have two objects of the same class configured differently. With annotations, you put them into a class, so every object of that class is usually the same.

+5


source







All Articles