【问题标题】:Deploying Spring app to Jetty将 Spring 应用程序部署到 Jetty
【发布时间】:2013-04-19 10:51:50
【问题描述】:

我希望 Jetty 运行我的 spring 应用程序。在带有 run-jetty-run 插件的 Eclipse 中,一切似乎都很好。当我将war文件(我用maven生成)复制到jetty 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>

【问题讨论】:

  • 您应该在 web.xml 中添加一个上下文加载器侦听器。 stackoverflow.com/questions/11014782/…
  • 没有任何变化。
  • 战争中有/WEB-INF/erastotenes-servlet.xml吗?尝试将战争解压到 /webapps。

标签: java spring jetty war


【解决方案1】:

这解决了问题:

  <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>

【讨论】:

  • 你能澄清一下是什么问题吗?
  • 项目为&lt;packaging&gt;webapp&lt;/packaging&gt;maven-war-plugin的默认配置。
猜你喜欢
  • 1970-01-01
  • 2021-07-25
  • 1970-01-01
  • 2015-01-25
  • 2018-10-31
  • 2014-05-03
  • 2016-01-16
  • 2014-12-25
  • 1970-01-01
相关资源
最近更新 更多