java - 最近更改后的 web.xml 值非法

标签 java eclipse spring spring-mvc servlets

每当我尝试在 Project Explorer 中扩展项目内容时,Eclipse 都会出现以下错误:

An internal error occurred during: "Loading descriptor for AppName.".
org.eclipse.emf.ecore.xmi.IllegalValueException: Value 'Container' 
is not legal. (platform:/resource/AppName/src/main/webapp/WEB-INF/web.xml, 81, 16)  

该项目是一个 spring mvc 应用程序,问题似乎是最近添加了 JavaMail 部分的 web.xml 部分的语法。

引发错误的代码行标记在以下代码段中:

<resource-ref>
  <description>
    Resource reference to a factory for javax.mail.Session
    instances that may be used for sending electronic mail
    messages, preconfigured to connect to the appropriate
    SMTP server.
  </description>
  <res-ref-name>
    mail/Session
  </res-ref-name>
  <res-type>
    javax.mail.Session
  </res-type>
  <res-auth>
    Container
  </res-auth> <!-- this line throws the error -->
</resource-ref>

这是我的web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>AppName</display-name>
  <description>Description of app.</description>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>AppName</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/mvc-core-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AppName</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>datatablesController</servlet-name>
    <servlet-class>com.github.dandelion.datatables.extras.servlet2.servlet.DatatablesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>datatablesController</servlet-name>
    <url-pattern>/datatablesController/*</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>httpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>httpMethodFilter</filter-name>
    <servlet-name>AppName</servlet-name>
  </filter-mapping>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>datatablesFilter</filter-name>
    <filter-class>com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>datatablesFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- added the following for JavaMail -->
  <resource-ref>
    <description>
      Resource reference to a factory for javax.mail.Session
      instances that may be used for sending electronic mail
      messages, preconfigured to connect to the appropriate
      SMTP server.
    </description>
    <res-ref-name>
      mail/Session
    </res-ref-name>
    <res-type>
      javax.mail.Session
    </res-type>
    <res-auth>
      Container
    </res-auth>
  </resource-ref>
</web-app>  

如何解决此错误?

最佳答案

删除空格,如下所示:

<res-auth>Container</res-auth>

关于java - 最近更改后的 web.xml 值非法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28707543/

相关文章:

java - 使用个人 X509 证书连接到 Android 应用程序中受 SSL 保护的 API?

java - 是否可以使用 JSON 发送文件

java - xlsx表的打印内容

java - FC_COLS 的原始类型 int 没有字段 inBlockSize

java - 使用@PreAuthorize时的安全配置

java - Hamcrest 比较系列

java - 在没有项目的情况下在 Eclipse 中导航导入

java - 从 TextView 中删除停用词

Spring mvc : Changing default Response format from xml to json

java - Spring REST URI 存在检查