私の目標は、tomcat-maven-plugin を使用していくつかの Web アプリケーションをデプロイし、それらの間でクロス コンテキストの相互作用を行うことです。これはプロトタイピング用です。そこで、2 つの war モジュール (core と webapp1) を作成し、適切な context.xml を両方の META-INF フォルダーに配置し、tomcat7 プラグインを構成しました。ただし、Web アプリケーションはデフォルトのコンテキスト構成でデプロイされました。一般的な Tomcat 7 コンテナーにデプロイすると、すべてが完璧に機能します。別の webbapp のコンテキストにアクセスできます。
私の質問は、私が間違っていることは何ですか? それとも、これは組み込みのTomcatの制限ですか(違いについては何も見つかりませんでしたが)?
ここに私のcontext.xmlがあります:
<Context crossContext="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
tomcat プラグインの設定 (重要かどうかはわかりませんが):
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/</path>
<port>8080</port>
<addContextWarDependencies>true</addContextWarDependencies>
<addWarDependenciesInClassloader>true</addWarDependenciesInClassloader> <warSourceDirectory>${project.build.directory}/${project.build.finalName}/</warSourceDirectory>
<webapps>
<webapp>
<groupId>lfcms-several-webapps-proto</groupId>
<artifactId>webapp1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
<webapp>
<groupId>lfcms-several-webapps-proto</groupId>
<artifactId>webapp2</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
</webapps>
</configuration>
</plugin>
コアサーブレットのコードは次のとおりです。
final ServletContext additionalContext = ctx.getContext("/webapp1");
if (additionalContext == null) throw new ServletException("can't get context of /webapp1");
final RequestDispatcher disp = additionalContext.getRequestDispatcher("/webapp1");
disp.include(req, resp);