目錄
[TOC]
## 修改pom文件
packaging修改為war
spring-boot-starter-web去除tomcat依賴
添加servlet依賴

添加新的tomcat運行方式




指定當前開發項目


改為/

## 繼承SpringBootServletInitializer重寫configure方法
`
~~~
package xxxx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
~~~
`
*****
寫個Contoller用于測試
~~~
package xxxxxx;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Example {
@RequestMapping("/CC")
String home() {
return "Hello World!1";
}
}
~~~
*****
## 點擊運行tomcat啟動服務

服務成功啟動

服務可以成功訪問
