5

Nowadays I have been practising Java EE. There are may annotations which simplify configuration of servlet container. Such as:

  • @WebServlet
  • @WebInitParam
  • @ServletSecurity
  • etc.

You can do the same thing in deployment descriptor: Web.xml Personally, I prefer annotations.

My questions are:

  • can I use annotations for any possible use-case of the Web.xml?
  • Any existing limitations, except that Java EE specific version needs to support annotations?

Best regards

2

Any existing limitations, except that Java EE specific version needs to support annotations?

One thing I know of is ordering.

From the Servlet 3.1 specs:

The order in which the Listeners, Servlets are loaded from the various framework jars / classes in the WEB-INF/classes or WEB-INF/lib is unspecified when using annotations. If ordering is important then look at the section for modularity of web.xml and ordering of web.xml and web-fragment.xml below. The order can be specified in the deployment descriptor only.

As for your first point:

can I use annotations for any possible use-case of the Web.xml?

Apart from that limitation, yes (I'm not aware of others, but there might be more). But even then people will try workarounds and still use annotations because they prefer that style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.