Tomcat 6.0.35 和 java 8

Tomcat 6.0.35 and java 8

我正在尝试将 spring 启动应用程序部署到 Tomcat 6.0.35。

我从 www.mkyong.com 下载示例应用程序并构建 .war 应用程序。我将它移动到 tomcat webapps 目录。

我可以访问 tomcat 6 主页和管理器,甚至可以部署应用程序,但是当我转到 http://localhost:8080/demo-0.0.1-SNAPSHOT 时,我得到 404 页面。

我没有收到任何错误,请参见下文:

catalina.2014-04-21.log:

   kwi 21, 2017 3:33:55 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
kwi 21, 2017 3:33:55 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
kwi 21, 2017 3:33:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 709 ms
kwi 21, 2017 3:33:55 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
kwi 21, 2017 3:33:55 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
kwi 21, 2017 3:33:55 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive spring-boot-web-thymeleaf-1.0.war
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive demo-0.0.1-SNAPSHOT.war
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
kwi 21, 2017 3:33:56 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
kwi 21, 2017 3:33:56 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
kwi 21, 2017 3:33:56 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/28  config=null
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1141 ms

catalina.out:

    kwi 21, 2017 3:33:55 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
kwi 21, 2017 3:33:55 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
kwi 21, 2017 3:33:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 709 ms
kwi 21, 2017 3:33:55 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
kwi 21, 2017 3:33:55 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
kwi 21, 2017 3:33:55 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive spring-boot-web-thymeleaf-1.0.war
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive demo-0.0.1-SNAPSHOT.war
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
kwi 21, 2017 3:33:56 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
kwi 21, 2017 3:33:56 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
kwi 21, 2017 3:33:56 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/28  config=null
kwi 21, 2017 3:33:56 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1141 ms

localhost.2017-04-21.log:

  kwi 21, 2017 3:33:56 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
kwi 21, 2017 3:33:56 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()

On tomcat 8 部署工作正常,但不幸的是我必须使用 tomcat 6.0.35.

我正在使用 java 1.8.0_121-b13 甲骨文。

我是不是漏掉了一些额外的配置?

我添加 spring-boot-legacy 依赖项:

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-legacy -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>

然后我在webapp/WEB-INF/目录下创建了web.xml并填充了:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mkyong.SpringBootWebApplication</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

最后,/logs/中的catalina.out文件:

INFO: Deploying web application archive spring-boot-web-thymeleaf-1.0.war

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)

2017-04-21 16:45:46.240  INFO 13420 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1492785946240 ms
2017-04-21 16:45:46.263  INFO 13420 --- [           main] org.apache.catalina.startup.Bootstrap    : Starting Bootstrap v6.0.35 on aleksander-K56CB with PID 13420 (/home/aleksander/apache-tomcat-6.0.35/bin/bootstrap.jar started by aleksander in /home/aleksander/apache-tomcat-6.0.35/bin)
2017-04-21 16:45:46.267  INFO 13420 --- [           main] org.apache.catalina.startup.Bootstrap    : No active profile set, falling back to default profiles: default
2017-04-21 16:45:46.778  INFO 13420 --- [           main] onConfigNonEmbeddedWebApplicationContext : Refreshing org.springframework.boot.legacy.context.web.AnnotationConfigNonEmbeddedWebApplicationContext@6a8658ff: startup date [Fri Apr 21 16:45:46 CEST 2017]; root of context hierarchy
2017-04-21 16:45:49.969  INFO 13420 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.legacy.context.web.AnnotationConfigNonEmbeddedWebApplicationContext@6a8658ff: startup date [Fri Apr 21 16:45:46 CEST 2017]; root of context hierarchy
2017-04-21 16:45:50.064  INFO 13420 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.mkyong.WelcomeController.welcome(java.util.Map<java.lang.String, java.lang.Object>)
2017-04-21 16:45:50.070  INFO 13420 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-04-21 16:45:50.070  INFO 13420 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-04-21 16:45:50.132  INFO 13420 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-21 16:45:50.132  INFO 13420 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-21 16:45:50.208  INFO 13420 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-21 16:45:51.215  INFO 13420 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-04-21 16:45:51.244  INFO 13420 --- [           main] org.apache.catalina.startup.Bootstrap    : Started Bootstrap in 6.368 seconds (JVM running for 8.515)
2017-04-21 16:45:51.274  INFO 13420 --- [           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'appServlet': initialization started
2017-04-21 16:45:51.296  INFO 13420 --- [           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'appServlet': initialization completed in 22 ms
kwi 21, 2017 4:45:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
kwi 21, 2017 4:45:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
kwi 21, 2017 4:45:51 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
kwi 21, 2017 4:45:51 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
kwi 21, 2017 4:45:51 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
kwi 21, 2017 4:45:51 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=1/21  config=null
kwi 21, 2017 4:45:51 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7930 ms

和浏览器页面:

太棒了!