Tomcat 6.0.35和java 8

时间:2017-04-21 13:40:26

标签: java spring tomcat spring-boot tomcat6

我试图将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()

在tomcat 8上部署正常,但不幸的是我必须使用tomcat 6.0.35。

我使用的是java 1.8.0_121-b13 oracle。

我是否错过了一些其他配置?

1 个答案:

答案 0 :(得分:1)

我添加了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

和浏览器页面: screenshot

大!