第一次springboot專案打成war包並部署在tomcat上
阿新 • • 發佈:2018-12-14
1.修改配置
(1)主程式
@SpringBootApplication public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application){ return application.sources(DemoApplication.class); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
(2)pom.xml
先將jar改成war,然後新增以下依賴
<!--移除springboot內建的tomcat--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
2.執行操作
Buid>>build Artifacts>>all Artifacts>>build
3.找到target底下.war檔案,複製修改檔名,然後放到tomcat資料夾下webapps啟動訪問
ps:
1.tomcat必須8以上
2.路徑必須加檔名
3.在idea中的ajax請求可以不加檔名,但是如果要打成war包釋出,那所有的請求路徑都要加檔名,否則只能訪問到index.html,其他頁面請求後臺時都報404
4.tomcat8以上不用配置環境變數