I followed a simple guide and created a spring-boot based web application on my local, using embedded tomcat, it works fine. The next step I am trying to deploy it onto a remote linux tomcat server. I followed these steps first:
(1) Update application’s main class to extend SpringBootServletInitializer
. SpringBootApplication
is my previous main class
public class WebInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootWebApplication.class);
}
}
@SpringBootApplication
public class SpringBootWebApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
}
@Controller
public class IndexController {
@RequestMapping("/")
String index(){
return "index";
}
}
(2) Update build configuration so that project produces a war file rather than a jar file.
<packaging>war</packaging>
(3) Mark the embedded servlet container dependency as provided. I do not have this dependency before only the spring-boot-starter-web
I just added one
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
(4) I also added app path in application.properties
server.context-path = /springbootdemo
After running maven-clean and maven-install I get my spring-boot-web-0.0.1-SNAPSHOT.war
and then put it into tomcat webapp in remote server, but I am getting 404 on both of them:
http://host:port/springbootdemo
http://host:port/spring-boot-web
http://host:port/spring-boot-web/springbootdemo
What should be the right path here to my app? When running on local it is running on http://localhost:8080/ without a app name. When I see server catalina.out logs there no exception and server get startup.