一起學習springboot(二):使用外接Tomcat啟動
阿新 • • 發佈:2018-12-18
- 修改pom.xml檔案,新增依賴,打包改成war格式
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.36</version>
<scope>provided</scope>
</dependency>
- 修改啟動類 SpringbootFirstApplication,繼承SpringBootServletInitializer,重寫configure方法
package com.example.springboot_first; 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 SpringbootFirstApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringbootFirstApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(SpringbootFirstApplication.class); } }
- 配置Tomcat(假設你的電腦上已經裝有Tomcat了)
這裡選擇tomcat得版本為8.5.20
配置工程訪問字尾,可以不配,最後 apply---->ok
- maven打包部署