Re: servlet annotations for URL mapping?
On Apr 30, 10:58 pm, Rex Mottram <r...@not.here> wrote:
Mike Schilling wrote:
Rex Mottram wrote:
Rex Mottram wrote:
And replace it annotations in the servlet itself.
Meant "replace it _with_ annotations ..." of course.
And the container, rather than reading web.xml, looks at every class
file in the webapp to see if it's annotated as a servlet? That sounds=
like a bad idea.
Maybe so, but it's a bad idea which is mandated by the latest revision
of the servlet spec. There are certain limitations - I believe it is
only required to examine the class files under WEB-INF/classes and in
jar files under WEB-INF/lib, and there's a way to turn off the search if
you don't want it.
Not just the servlet spec, either: classpath scanning for annotations
is a fairly well-established practice at this point. It's mandated
(indirectly) by the EJB 3 and JPA specifications, which allow for
descriptor-free deployment of EJBs and mapped entities respectively;
it's also used in a number of third-party frameworks, including
notably Spring 2.5 and Struts 2.
Looking at the servlet 2.5 spec, I don't see any annotations mentioned
that could be used to control servlet deployment (as, eg, @Stateless,
@Stateful, @Local, and @Remote are used to control EJB deployment).
This is consistent with the servlet 2.5 API docs, which contain no
annotation types. I believe you're out of luck, at least until the
next servlet specification, if you want to stay within Sun's
specification constellation.
However, I've had extremely positive experiences using annotations to
configure Spring Web MVC. See <http://static.springframework.org/
spring/docs/2.5.x/reference/mvc.html#mvc-annotation> for details; it
can be deployed inside any servlet container with little difficulty
and does allow for annotation-driven configuration.
-o