【问题标题】:How to deploy Spring Boot app to Tomcat 6 Servlet 2.5如何将 Spring Boot 应用程序部署到 Tomcat 6 Servlet 2.5
【发布时间】:2014-08-17 14:42:50
【问题描述】:

我使用 Spring Boot 创建了一个常见问题解答。它需要部署到 tomcat 6 服务器(servlet 2.5)。我需要配置当前的父 java app(war) web.xml 以将所有请求指向 url 模式“/faq/*”,例如,指向我的 spring boot FAQ 应用程序。我已将 FAQ.jar 文件复制到父应用程序的 lib 文件夹中。但我不确定如何在父应用程序的 web.xml 中配置/注册 spring boot servlet 和 servlet 映射。

使用 spring boot legacy 示例。我将 spring boot 应用程序与依赖项 jar 文件一起放在父应用程序 lib 文件夹中。我将此代码块添加到父应用程序的 web.xml 中。

 <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>

但是当我启动 Tomcat 时,我收到以下错误。

2014 年 6 月 30 日上午 12:17:23 org.apache.catalina.core.StandardContext listenerStart 严重:向类 org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener 的侦听器实例发送上下文初始化事件的异常 java.lang.IllegalAccessError: 试图访问方法 org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(Ljava/lang/Class;Ljava/lang/ClassLoader;)Ljava/util/List;从类 org.springframework.boot.SpringApplication 在 org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:355) 在 org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:346) 在 org.springframework.boot.SpringApplication.initialize(SpringApplication.java:222) 在 org.springframework.boot.SpringApplication.(SpringApplication.java:198) 在 org.springframework.boot.builder.SpringApplicationBuilder.(SpringApplicationBuilder.java:83) 在 org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:48) 在 org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 在 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 在 org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:897) 在 org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:873) 在 org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) 在 org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095) 在 org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 在 java.util.concurrent.FutureTask.run(FutureTask.java:138) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:619) 2014 年 6 月 30 日上午 12:17:23 org.apache.catalina.core.StandardContext startInternal 严重:错误 listenerStart

凯维凯夫

【问题讨论】:

    标签: spring deployment spring-boot servlet-2.5


    【解决方案1】:

    Spring Boot 官方不支持 Servlet 2.5,但它并不需要太多的工作。您可能会发现这很有用:https://github.com/scratches/spring-boot-legacy。示例:https://github.com/scratches/spring-boot-sample-gae。

    【讨论】:

    • 感谢您的回复... 使用 spring boot legacy 示例,更改父应用程序的 web.xml 文件并将我的引导应用程序放在 lib 文件夹中。但是当我启动 Tomcat 时,我收到以下错误:严重:向 org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener java.lang.IllegalAccessError 类的侦听器实例发送上下文初始化事件的异常:试图访问方法 org. springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(Ljava/lang/Class;Ljava/lang/ClassLoader;)Ljava/util/List;来自类 org.springframework.boot.SpringApplication
    • 看起来可能是类路径问题?检查您的 WEB-INF/lib 和容器中的任何共享库是否有旧版本。或者你的容器中有一个`SecurityManager?
    • 所以我必须将我的 Spring Boot 应用程序(FAQ.jar)的每个依赖 jar 添加到父应用程序的 lib 文件夹中?连同应用本身?
    • 我真的不知道你所说的“父应用程序”是什么意思,但是战争是自包含的,所以任何需要在你的应用程序的类路径上的东西都必须在那里。您没有在构建工具(maven、gradle 等)中使用依赖管理系统吗?
    • 战争没有使用maven依赖,但是spring boot jar是......所以我将依赖jar添加到战争-> lib中。
    猜你喜欢
    • 2016-01-16
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2014-09-04
    • 2018-03-16
    • 2021-07-25
    相关资源
    最近更新 更多