2016-04-18 47 views
0

我遵循一個簡單的指南,並在本地使用嵌入式tomcat創建了一個基於spring-boot的web應用程序,它工作正常。下一步我試圖將它部署到遠程linux tomcat服務器上。我首先執行了以下步驟:在tomcat上安裝spring-boot應用程序

(1)更新應用程序的主類以擴展SpringBootServletInitializerSpringBootApplication是我以前的主類

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日誌時,沒有任何異常和服務器啓動。

回答

1

server.context-path將WAR文件部署到外部容器時不起作用。

Tomcat使用戰爭的全名減去後綴.war作爲應用的上下文路徑。假設您將spring-boot-web-0.0.1-SNAPSHOT.war複製到Tomcat的webapps目錄中,您的應用程序將在http://localhost:8080/spring-boot-web-0.0.1-SNAPSHOT處可用。

+0

謝謝!這是一個很大的疑問,我總是有:)現在我明白了。 – feichangh

-1

你可以看到我的回答here

答案還包含一個指向您可以構建和部署到Tomcat的演示項目的鏈接。