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

时间:2015-02-24 22:23:53

标签: 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>  

如何解决此错误?

2 个答案:

答案 0 :(得分:3)

删除这样的空格:

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

答案 1 :(得分:1)

在res-auth标签中,您提到它有容器。您是否在服务器容器中定义了邮件/会话?在weblogic服务器或tomcat server.xml中。

问题可能是容器中缺少mail / Session的引用。

http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/web_xml.html