How to include other configuration files in web.xml

I need to define many servlets, but I do not want to write the configuration in web.xml.

Is it possible to define some servlet configuration files and include them in web.xml? Or is there another way to split the web.xml file into multiple files?

+6
source share
2 answers

The Servlet 3.0 specification contains the new @WebServlet annotation, which can be used to declare servlets in code without the need for web.xml. For more information, see Section 8.1.1 of the Servlet 3.0 Specification and view javadoc .

 @WebServlet("/myServlet") public class MyServlet extends HttpServlet { //... } 

In addition, Servlet 3.0 introduced the concept of web fragments, which addresses your second issue of splitting web.xml into multiple files. These fragments may contain part (or all) of the web deployment descriptor, including annotations of the META-INF/web-fragment.xml file and / or servlet in the jar files in the directory of your WEB-INF/lib web module. For more information, see Section 8.2 of the Servlet 3.0 Specification.

+5
source

The Servlet 3.0 specification allows servlets to be declared through Java annotations - therefore there are no entries in the web.xml file. Other than this, I do not know any "included" functions.

+3
source

Source: https://habr.com/ru/post/903071/


All Articles