Jetty 8中的目录列表与welcomeServlet问题

时间:2013-09-04 15:12:37

标签: tomcat spring-mvc maven-jetty-plugin jetty-8

我们在生产中部署了Tomcat上的servlet 3 Spring MVC Web应用程序。

应用程序(带有小调整)也应该能够在Jetty 8上运行。目前这仅用于开发环境,主要用于开发机器上的集成测试。

在我们的CI系统上,战争部署在Tomcat上,应用程序正在运行并通过所有测试。

在Jetty 8上运行时,以/结尾的所有测试都将失败,因为返回的是目录列表而不是欢迎文件。

要解决此问题,我们尝试通过配置Jetty DefaultServlet来禁止目录列表:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<!-- Configure Jetty DefaultServlet to disallow dir listing and explicitly allow welcomeservlets (a welcomeservlet in jetty terms is a <welcome-file> tag in web.xml that is pointing to a URI(file name) matched by a servlet)
    NOTE: all init-params supported by org.eclipse.jetty.servlet.DefaultServlet can be set directly on the WebAppContext using setInitParameter and prefixing the init-param with  'org.eclipse.jetty.servlet.Default.' - e.g. 'org.eclipse.jetty.servlet.Default.dirAllowed'
-->
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.dirAllowed</Arg>
    <Arg>false</Arg>
</Call>
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.welcomeServlets</Arg>
    <Arg>true</Arg>
</Call>
<Call name="setInitParameter">
    <Arg>org.eclipse.jetty.servlet.Default.redirectWelcome</Arg>
    <Arg>true</Arg>
</Call>

从我们的pom中引用它:

<plugin>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>${jetty.maven.plugin.version}</version>
                        <configuration>
                            <contextXml>${basedir}/src/test/resources/jetty-context.xml</contextXml>
                        ...
                        </configuration>
</plugin>

然而,现在我们在通过测试执行GET / citizen /时找不到404。如果我们手动将index.html添加到URL,那么我们的Spring静态资源处理程序就可以很好地提供文件。

我是否可以在Jetty上设置更多的init-params,使其表现得像Tomcat一样关于welcome-file?

0 个答案:

没有答案