• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annotation Scanning.  RSS feed

 
Pankaj Shet
Ranch Hand
Posts: 320
Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Guys,
I am trying to learn servlet 3.
Servlet 3.x uses Annotations in web applications,
How are those annotations scanned by the containers automatically??
How does container work?
Thanks,
-Pankaj
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pankaj Shet wrote:
How are those annotations scanned by the containers automatically??

Typically reflections is used.

Pankaj Shet wrote:
How does container work?

Different containers work in different ways. You have to check the manuals and source code for the container that you are interested in. Some containers don't even have open source code so you might never know. Generally you shouldn't need to know all those details. If you really want to get close then you should at least read the several documents that make us the EE specification to find out what containers are required to do.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a web application is deployed, one of the first things that is done is that its web.xml file is digested.

In every J2EE web application, there are a pair of "deployment descriptor" files. A platform-independent deployment descriptor (/WEB-INF/web.xml) and a platform-dependent deployment descriptor (In Tomcat, it's the "Context" element).

The platform-independent deployment descriptor, as its name indicates contains deployment information that is independent of which container you are deploying into. Stuff like servlet definitions, servlet URL mapping, security information and so forth.

In JEE, however, it is no longer required to actually code all that information in web.xml, as the same information can be packaged directly in the classes that it applies to by using annotations. You can still use web.xml to add information that isn't class-related, and a web.xml element will override an annotated class, if given. However the way that JEE containers deploy webapps is by first scanning the webapp classes to build a model web.xml from their annotations, then digesting the physical web.xml file (if present) to augment and override that model.

As far as I can deduce, this scanning process involves examining every class in the WAR portion of the application classpath. But since that can potentially be a lot of classes, I may have missed a limiting mechanism.

A container is just what its name says. It contains various services and applications. In the minimalistic Tomcat container, the primary services are those needed to support servlets and JSPs. For full-stack containers you can have additional services such as JMS and EJB. The JEE spec defines exactly how these various services must behave, but not how they must be implemented. A container can be implemented any way the author of the container wants as long as it adheres to the functional specifications. The Tomcat container, for example, is comprised of various different types of javabeans that provide component services (Connectors, Hosts, Engines and so forth) and these beans are wired together to provide the actual Tomcat functions. These component services, in turn, often draw on generally-available generic JEE services (such as the apache Digester and BeanUtils).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!