Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How the Annotations are Processed?

 
mahudees waran
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one please help me out to understand how the annotations are processed by the container? and how does container use it when compared to DD?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Container will scan the classes when they are deployed. It will probably use methods like Class#getAnnotation and Class#getAnnotations on the class, on its fields and on its methods. It does it once, then parses the DD and overrides any existing settings.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Christophe explained. Java has a reflection API that allows to inspect class information at runtime.
 
mahudees waran
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply guys.

Christophe,
Do you mean that the container first reads the DD and then overrides the DD configurations according to the annotations in classes while loading them.Also loading the classes which does mean that, Every class in the application will be loaded while the server startup? where as in case of servlets the servlet class is loaded on the first request untill we specifically mention it to load while server startup using
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DD overrides annotations.

I don't know detail, but I guess container just read class metadata, not create instance of every class.
When use reflection API to inspect class metadata, we don't need to create an instance of class. Anyway, a class itself is some kind of instance, but you don't need to worry about that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic