tomcat将模块war部署到子url路径

时间:2017-03-29 09:03:10

标签: java spring tomcat web war

我有一个多模块maven项目,其结构如下所示:

app                // parent/root project folder
 |- src         
 |- target
      |- app.war   // common features
 |- app-payment    // child/module folder
        |- src   
        |- target
             |- app-payment.war  // shop/pay features

如何将两个war文件映射到下面的网址?

requests for    
   localhost:8080/app/payment   --goto-->   $CATALINA_HOME/webapps/app-payment.war (or any other locations, doesn't matter)
other requests for
   localhost:8080/app           --goto-->   $CATALINA_HOME/webapps/app.war

web.xml - &gt; <servlet-mapping> <url-pattern>/</url-pattern>都是<Context>

我正在使用tomcat 8.5并希望保留默认设置(例如,不要在server.xml中添加 //.... cell.ImageviewLabel2.backgroundColor = [UIColor greenColor]; // because tableview reuse uitableviewcell, so you must reset hidden status for lable cell.ChatLabel2.hidden = NO; cell.ChatLabel1.hidden = NO; if([Replychat[indexPath.row] valueForKey:@"bot"] != NULL) //.... ,请保留autoDeploy = true)。所以可能在关于上下文的单词中提供的方法 https://tomcat.apache.org/tomcat-8.5-doc/deployer-howto.html不起作用(无论如何都没有尝试过)。

如果这是一个XY问题......是否正确使用/修改tomcat来实现这样的url模式?或者我应该更改项目设置(或设计)?它是一个spring-mvc项目,整个春天 - * .xml就像一个神话......

catalina.2017-03-29.log:

29-Mar-2017 17:28:49.472 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
29-Mar-2017 17:28:49.472 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.5
29-Mar-2017 17:28:49.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program_Files\tomcat-8.5.5\webapps\payment.war
29-Mar-2017 17:28:49.505 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
29-Mar-2017 17:28:51.071 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
29-Mar-2017 17:28:52.480 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Program_Files\tomcat-8.5.5\webapps\payment.war has finished in 2,985 ms
29-Mar-2017 17:28:52.482 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program_Files\tomcat-8.5.5\webapps\docs
29-Mar-2017 17:28:52.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\Program_Files\tomcat-8.5.5\webapps\docs has finished in 12 ms
29-Mar-2017 17:28:52.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\Program_Files\tomcat-8.5.5\webapps\examples

2 个答案:

答案 0 :(得分:0)

尝试更改war文件的context.xml

 <Context antiJARLocking="true" path="/app/payment"/>

默认情况下,它是

 <Context antiJARLocking="true" path="/app-payment"/>

答案 1 :(得分:0)

我知道这是一篇旧文章,但以为我会分享。在拥有Web应用程序的地方,我必须做类似的事情,然后在核心应用程序的相同目录名下运行另一个独立的Web应用程序。所以像...

https://www.example.com/webapp (main app)
https://www.example.com/webapp/subapp (sub-app)

为此,我将其部署到Tomcat webapps 文件夹中,如下所示:

../webapps/webapp.war
../webapps/webapp#subapp.war

对我来说就像是一种魅力。如果我没记错的话,无需任何其他配置即可完全支持此功能(Tomcat v7和v8 ...尚未尝试v9)。