使用WebApplicationInitializer上下文路径的Tomcat 9 Spring App不起作用

时间:2019-06-08 08:36:09

标签: spring-mvc tomcat

我有一个Spring 4.3.6 App,我正在从Tomcat 8.5服务器迁移到另一台Linux主机上的Tomcat 9.0.20服务器。

在TC 8.5服务器上一切正常。

docBase包含静态html和war文件。战争并没有在启动期间解压,并且日志显示“正在初始化Spring FrameworkServlet'dispatcher'”。我可以浏览到静态内容,但是浏览到Web应用程序测试页面时,我会得到404-请参阅URL:

Static Content

Web App Test Page

下面是catalina.log的一些内容:

08-Jun-2019 18:54:09.548 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/home/carpenterdev/tanglemydata.dev/tanglemydataapp.war]
08-Jun-2019 18:54:19.968 INFO [main] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
08-Jun-2019 18:54:20.212 INFO [main] 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.
08-Jun-2019 18:54:20.216 INFO [main] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
08-Jun-2019 18:54:37.082 INFO [main] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcher'
08-Jun-2019 18:54:37.285 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/home/carpenterdev/tanglemydata.dev/tanglemydataapp.war] has finished in [27,736] ms
08-Jun-2019 18:54:37.287 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/carpenterdev/tanglemydata.dev/assets]
08-Jun-2019 18:54:37.337 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/carpenterdev/tanglemydata.dev/assets] has finished in [50] ms
08-Jun-2019 18:54:37.363 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
08-Jun-2019 18:54:37.437 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
08-Jun-2019 18:54:37.505 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-jsse-nio-127.0.0.1-8443"]
08-Jun-2019 18:54:37.564 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [71,758] milliseconds

这是我的主机元素:

    <Host name="tanglemydata.dev" appBase="/home/carpenterdev/tanglemydata.dev" unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
       <Context path="" reloadable="true" docBase="/home/carpenterdev/tanglemydata.dev" /> 
    </Host>

这是我的docBase的样子:

enter image description here

感谢您的帮助!

鲍勃

1 个答案:

答案 0 :(得分:0)

我是OP,已经解决了问题。

问题归结于Apache2的httpd.conf中<VirtualHost>元素中的ServerName,与Tomcat的server.xml的<Host>元素中指定的名称不匹配。

httpd.conf和server.xml必须使用与DNS注册完全相同的名称。在我的原始帖子中,您看到在server.xml中,我指定了:

<Host name="tanglemydata.dev"

但是httpd.conf是从DNS获取的,它的输入方式为:

ServerName tanglemydata.carpenterdev.com

因此,对sever.xml的更改是这样的:

<Host name="tanglemydata.carpenterdev.com"

此外,在server.xml中,我添加了一个别名:

<Alias>tanglemydata.dev</Alias>

希望这对其他人有帮助。

鲍勃