0

我希望 Jetty 运行我的 spring 应用程序。在带有 run-jetty-run 插件的 Eclipse 中,一切似乎都很好。当我将 war 文件(我使用 maven 生成)复制到码头 webapps,然后输入 url 时,出现错误:

   org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/erastotenes-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/erastotenes-servlet.xml]

我的 web.xml:

<web-app id="walladverts" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
    <servlet-name>erastotenes</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>erastotenes</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-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>

编辑 添加了上下文侦听器,但仍然没有帮助:

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/erastotenes-servlet.xml
    </param-value>
</context-param>
4

1 回答 1

0

这解决了问题:

  <build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <webXml>src/webapp/WEB-INF/web.xml</webXml>
      <webResources>
        <resource>
          <!-- this is relative to the pom.xml directory -->
          <directory>src/webapp/</directory>
        </resource>
      </webResources>
    </configuration>
  </plugin>
</plugins>

于 2013-04-19T12:15:22.253 回答