【问题标题】:Maven project works fine in eclipse but doesn't work when deployed to tomcatMaven 项目在 Eclipse 中运行良好,但在部署到 tomcat 时无法运行
【发布时间】:2021-11-13 20:48:51
【问题描述】:

当我手动将 war 文件部署到 tomcat 时出现 404 错误。但是,如果我在 Eclipse 中运行 maven build spring-boot:run 那么它工作正常,我可以通过 localhost:8080 访问该应用程序。

这是我正在尝试运行的应用程序https://github.com/mokarakaya/spring-boot-multi-module-maven

知道为什么会出现此错误吗?

/**
 * since basePackage includes com.apiDemo.* and api module is imported, api components will also be invoked.
 */
@Configuration
@ComponentScan(basePackages = "com.*")
@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(WebApplication.class, args);
    }
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl");
    }
}

@Piotr P. Karwasz 谢谢它现在可以在 tomcat 上运行,但我无法执行任何操作。更新和创建按钮会产生 405 或 404 错误。

【问题讨论】:

标签: java eclipse maven tomcat


【解决方案1】:

您的问题是Why it is necessary to extend SpringBootServletInitializer while deploying it to an external tomcat 的一个小变化。你扩展了类,但同时重写了最重要的方法(参见ServletContainerInitializer#onStartup的文档):

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl");
    }

您应该添加对super.onStartup的调用:

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl");
        super.onStartup(servletContext);
    }

【讨论】:

  • 它现在可以工作,但我无法执行任何操作,如更新或创建。知道为什么吗?添加截图
  • 这是一个完全不同的问题:您的 JavaScript 代码调用 /sessionOperations 而不是 /<path to api>/sessionOperations
  • 我该如何解决? api 路径是什么?
猜你喜欢
  • 2011-06-18
  • 1970-01-01
  • 2018-11-03
  • 2012-07-05
  • 1970-01-01
  • 2011-04-12
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
相关资源
最近更新 更多