我正在尝试将一个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}
After reading a number of pages and question-answers I added following to my 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>
I ran"mvn package"and got WAR file (size 250Mb), which I put into "webapps" folder.
- I started Tomcat and am able to see my app listed, in my case "/highlighter-1.0-SNAPSHOT".
- Clicking on the link for the app results in "Status 404" page.
- When I run Spring Boot app just by itself, without container it runs on localhost:7777, but there is nothing there when I run it in Tomcat.
SpringBootServletInitializer
类并重写了它的configure
方法? - Andy Wilkinson09-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()
- Ajay Yadav