How to deploy Spring Boot app to Tomcat 6 Servlet 2.5

半腔热情 提交于 2019-12-09 13:07:37

问题


I created a FAQ using spring boot. it needs to be deployed to a tomcat 6 server (servlet 2.5). I need to configure the current parent java app(war) web.xml to point all request to url pattern "/faq/*" for example, to my spring boot FAQ app. I've copied the FAQ.jar file into the lib folder of the parent app. But I'm not sure how to configure/register the spring boot servlet and servlet mapping within the web.xml of the parent application.

Using the spring boot legacy sample.. I placed my spring boot app in the parent app lib folder along with the dependency jar files. I added this code block to the web.xml of the parent app.

 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>faq.Application</param-value>
 </context-param>

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

  <filter>
      <filter-name>metricFilter</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>

<filter-mapping>
    <filter-name>metricFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>SpringServlet</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>SpringServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

But when I start up Tomcat, I get the following error.

Jun 30, 2014 12:17:23 AM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener java.lang.IllegalAccessError: tried to access method org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(Ljava/lang/Class;Ljava/lang/ClassLoader;)Ljava/util/List; from class org.springframework.boot.SpringApplication at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:355) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:346) at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:222) at org.springframework.boot.SpringApplication.(SpringApplication.java:198) at org.springframework.boot.builder.SpringApplicationBuilder.(SpringApplicationBuilder.java:83) at org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:48) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Jun 30, 2014 12:17:23 AM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart

KevyKev


回答1:


Spring Boot doesn't support Servlet 2.5 officially, but it doesn't take a lot to make it work. You might find this useful: https://github.com/scratches/spring-boot-legacy. Sample here: https://github.com/scratches/spring-boot-sample-gae.



来源:https://stackoverflow.com/questions/24435718/how-to-deploy-spring-boot-app-to-tomcat-6-servlet-2-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!