SpringBoot將項(xiàng)目打成war包步驟解析
1.修改pom.xml文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>top.ytheng</groupId>
<artifactId>springboot-demo</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
<build>
<finalName>myspringboot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.添加控制器Controller
package top.ytheng.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/file")
public class FileController {
@RequestMapping("/testpath")
@ResponseBody
private Object testPath() {
return "Success";
}
}
3.添加啟動(dòng)類
package top.ytheng.demo;
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 {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
}
4.右鍵項(xiàng)目依次執(zhí)行Run As -> Maven Clean 和 Maven Install,會(huì)在target目錄下生成war包

5.安裝Tomcat(注意:項(xiàng)目里面的端口和Tomcat保持一致,建議為8080,否則到時(shí)訪問(wèn)url會(huì)報(bào)錯(cuò))
將War包拷貝到Tomcat的webapps目錄下面

啟動(dòng)Tomca,會(huì)自動(dòng)將War包生成文件夾

6.訪問(wèn)路徑
注意:訪問(wèn)路徑要加上項(xiàng)目名稱
http://localhost:8080/myspringboot/file/testpath
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Springboot項(xiàng)目監(jiān)聽(tīng)器失效問(wèn)題解決
- 超個(gè)性修改SpringBoot項(xiàng)目的啟動(dòng)banner的方法
- Spring Boot項(xiàng)目維護(hù)全局json數(shù)據(jù)代碼實(shí)例
- Spring Boot 項(xiàng)目設(shè)置網(wǎng)站圖標(biāo)的方法
- SpringBoot多模塊項(xiàng)目框架搭建過(guò)程解析
- 在 Spring Boot 項(xiàng)目中實(shí)現(xiàn)文件下載功能
- spring boot項(xiàng)目快速構(gòu)建的全步驟
相關(guān)文章
解決Springboot整合shiro時(shí)靜態(tài)資源被攔截的問(wèn)題
這篇文章主要介紹了解決Springboot整合shiro時(shí)靜態(tài)資源被攔截的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01
Spring security實(shí)現(xiàn)記住我下次自動(dòng)登錄功能過(guò)程詳解
這篇文章主要介紹了Spring security實(shí)現(xiàn)記住我下次自動(dòng)登錄功能過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
Java 5個(gè)人坐在一起(有關(guān)第五個(gè)人歲數(shù)的問(wèn)題)
利用遞歸的方法,遞歸分為回推和遞推兩個(gè)階段。要想知道第五個(gè)人歲數(shù),需知道第四人的歲數(shù),依次類推,推到第一人(10歲),再往回推,需要的朋友可以參考下2017-02-02
Mybatis如何使用@Mapper和@MapperScan注解實(shí)現(xiàn)映射關(guān)系
這篇文章主要介紹了Mybatis使用@Mapper和@MapperScan注解實(shí)現(xiàn)映射關(guān)系,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10
Spring Cloud Feign組成配置過(guò)程解析
這篇文章主要介紹了Spring Cloud Feign組成配置過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
java開(kāi)發(fā)環(huán)境的完整搭建過(guò)程
這篇文章主要給大家介紹了關(guān)于java開(kāi)發(fā)環(huán)境的完整搭建過(guò)程,文中介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
Java日期格式化如何避免YYYY引發(fā)的時(shí)間異常
在編程中,日期格式化是一個(gè)常見(jiàn)的任務(wù),使用不同的格式化選項(xiàng)可能會(huì)導(dǎo)致一些意外的結(jié)果,下面我們就來(lái)學(xué)習(xí)一下Java如何避免YYYY引發(fā)的時(shí)間異常吧2023-11-11

