我遵循一個簡單的指南,並在本地使用嵌入式tomcat創建了一個基於spring-boot的web應用程序,它工作正常。下一步我試圖將它部署到遠程linux tomcat服務器上。我首先執行了以下步驟:在tomcat上安裝spring-boot應用程序
(1)更新應用程序的主類以擴展SpringBootServletInitializer
。 SpringBootApplication
是我以前的主類
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)更新構建配置,使項目產生戰爭文件,而不是一個jar文件。
<packaging>war</packaging>
(3)標記所提供的嵌入式servlet容器依賴項。我沒有這種依賴性我只是說以前只有spring-boot-starter-web
一個
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
在application.properties
server.context-path = /springbootdemo
(4)我還添加應用程序路徑運行Maven的清潔和Maven安裝我拿到後我spring-boot-web-0.0.1-SNAPSHOT.war
然後把它放到tomcat的webapp在遠程服務器上,但我對他們兩人獲得404:
http://host:port/springbootdemo
http://host:port/spring-boot-web
http://host:port/spring-boot-web/springbootdemo
我應該是正確的路徑在這裏我的應用程序?在本地運行時,它在http://localhost:8080/上運行,沒有應用程序名稱。當我看到服務器catalina.out日誌時,沒有任何異常和服務器啓動。
謝謝!這是一個很大的疑問,我總是有:)現在我明白了。 – feichangh