Maven 项目在 eclipse 中运行良好,但在部署到 tomcat 时不起作用
Maven project works fine in eclipse but doesn't work when deployed to tomcat
手动将 war 文件部署到 tomcat 时出现 404 错误。但是如果我 运行 maven 在 eclipse 中构建 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 错误。
你的问题是 . You extend the class, but at the same time override the most important method (see the documentation of 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);
}
手动将 war 文件部署到 tomcat 时出现 404 错误。但是如果我 运行 maven 在 eclipse 中构建 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 错误。
你的问题是 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);
}