サーブレット 3 Spring MVC Web アプリケーションを本番環境の Tomcat にデプロイしました。
アプリケーションは (わずかな調整で) Jetty 8 でも実行できるはずです。現在、これは開発環境でのみ使用され、主に開発マシンでの統合テストに使用されています。
私たちの CI システムでは、戦争は Tomcat に展開されており、アプリケーションは動作しており、すべてのテストに合格しています。
Jetty 8 で実行すると、ウェルカム ファイルではなくディレクトリ リストが返されるため、/ で終わる URL を取得するすべてのテストが失敗します。
これを回避するために、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 not found が返されるようになりました。URL に手動で index.html を追加すると、Spring の静的リソース ハンドラーによってファイルが適切に処理されます。
ウェルカムファイルに関してTomcatが行うように動作させるためにJettyに設定できるinit-paramsは他にありますか?