久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

SpringBoot將項目打成war包步驟解析

瀏覽:5日期:2023-05-28 11:11:41

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.添加啟動類

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;@SpringBootApplicationpublic 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.右鍵項目依次執行Run As -> Maven Clean 和 Maven Install,會在target目錄下生成war包

SpringBoot將項目打成war包步驟解析

5.安裝Tomcat(注意:項目里面的端口和Tomcat保持一致,建議為8080,否則到時訪問url會報錯)

將War包拷貝到Tomcat的webapps目錄下面

SpringBoot將項目打成war包步驟解析

啟動Tomca,會自動將War包生成文件夾

SpringBoot將項目打成war包步驟解析

6.訪問路徑

注意:訪問路徑要加上項目名稱

http://localhost:8080/myspringboot/file/testpath

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 樟树市| 渭南市| 乐至县| 金华市| 德格县| 巧家县| 葵青区| 渭源县| 瑞丽市| 平阴县| 开原市| 高陵县| 留坝县| 繁昌县| 石河子市| 宜君县| 普陀区| 会理县| 方山县| 沅陵县| 台中县| 福州市| 张家界市| 临潭县| 东乌| 堆龙德庆县| 固始县| 永平县| 永登县| 南华县| 大关县| 靖西县| 米易县| 康定县| 内乡县| 交城县| 合川市| 常德市| 班戈县| 阿巴嘎旗| 昂仁县|