【发布时间】:2015-03-10 08:57:17
【问题描述】:
我正在尝试将 Spring Boot 应用程序部署到 Tomcat,因为我想部署到 AWS。 我创建了一个 WAR 文件,但它似乎无法在 Tomcat 上运行,即使它是可见的。
详情:
0. 这是我的应用程序:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class App {
public static void main(String[] args) {
SpringApplication.run(SampleController.class, args);
}
}
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/help")
@ResponseBody
String home() {
String input = "Hi! Please use 'tag','check' and 'close' resources.";
return input;
}
}
application.properties 有以下内容:
server.port=${port:7777}
-
在阅读了一些pages 和question-answers 之后,我在我的POM 中添加了以下内容:
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.niewlabs</groupId> <artifactId>highlighter</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <java.version>1.8</java.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> 我运行“mvn package”并得到了 WAR 文件(大小 250Mb),我将其放入“webapps”文件夹中。
- 我启动了 Tomcat,并且能够看到我的应用程序已列出,在我的例子中是“/highlighter-1.0-SNAPSHOT”。
- 单击应用程序的链接会导致“状态 404”页面。
- 当我单独运行 Spring Boot 应用程序时,没有容器它在 localhost:7777 上运行,但是当我在 Tomcat 中运行它时什么都没有。
更新: 还有一个reference。不确定它有多大用处。
【问题讨论】:
-
您是否扩展了
SpringBootServletInitializer并覆盖了它的configure方法? -
不,我在 Spring Guide WAR 说明中没有看到任何提及。可以给我一个链接或详细信息吗?
-
@AndyWilkinson 谢谢你的提示。我在 Spring Guide [docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/….但我的应用仍然无法在 Tomcat 上运行。
-
我遵循了文档的所有步骤,但仍然得到 404 。从 tomcat localhost 日志中,似乎已检测到应用程序。
09-Nov-2019 11:19:59.676 INFO [main] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath 09-Nov-2019 11:20:12.722 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized() -
@AjayYadav 你是怎么解决的?
标签: spring maven tomcat spring-boot