1. 程式人生 > >servlet3.0 @WebServlet註解無效的情況

servlet3.0 @WebServlet註解無效的情況

web clas pre 16px jcp span complete 時也 -a

web.xml文件中的metadata-comcomplete屬性的作用:

  該屬性指定當前的部署描述文件是否是完全的。如果設置為true,則容器在部署時只依賴部署描述文件,忽略所有的註解(同時也會跳過web-fragment.xml的掃描,亦即禁用可插性支持);如果設置為false或不配置該屬性,則表示啟用註解支持(和可插性支持)。

註解有效的web.xml(metadata-complete="false"或者直接刪除)

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false" version="3.1"> </web-app>

註解無效的web.xml(metadata-complete="true")

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="true" version="3.1"> </web-app>

servlet3.0 @WebServlet註解無效的情況