news 2026/6/23 19:52:29

两个步骤,打包war,tomcat使用war包

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
两个步骤,打包war,tomcat使用war包

资源代码:

https://download.csdn.net/download/hashiqimiya/92455258

如上

了解资源代码:

写了一个controller代码,控制接口对应该运行的函数。

package org.example.testproducttomcatwar; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public String hello() { return "Spring Boot WAR 项目成功运行!"; } }

application的代码:

package org.example.testproducttomcatwar; 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 TestproducttomcatwarApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(TestproducttomcatwarApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(TestproducttomcatwarApplication.class); } }

在这段代码中,一定要继承父类并复写configure函数。

为什么要写configure函数?

是为了让导出的war包给tomcat使用的时候可以给tomcat识别到并调用

TestproducttomcatwarApplication.class

依赖pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.0.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>org.example</groupId> <artifactId>testproducttomcatwar</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- 打包方式修改成 war --> <packaging>war</packaging> <name>testproducttomcatwar</name> <description>testproducttomcatwar</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- 排除内置 Tomcat --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- 使用外部容器时提供 Tomcat 运行环境 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

运行操作:

一、

idea运行

资源里的testproducttomcatwar项目,改项目终端运行mvn clean install,

生成war包

二、

将1中的war包粘贴到项目

运行tomcattest项目时需要配置,

配置如下:

添加后

在配置里修改url

运行后,得到效果:

。。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/23 14:19:12

idea修改maven的刷新引入依赖快捷键

在 IntelliJ IDEA 里&#xff0c;Load Maven Changes 对应的是当你修改 pom.xml 或者依赖后&#xff0c;手动刷新 Maven 项目的操作。你也可以给它自定义快捷键。具体步骤如下&#xff1a;1. 打开快捷键设置Windows/Linux: File → Settings → KeymapmacOS: IntelliJ IDEA → …

作者头像 李华
网站建设 2026/6/23 19:51:17

纯电动汽车Simulink仿真模型建模详细步骤。 通过文档的形式,跟着文档一步一步操作,既可以...

纯电动汽车Simulink仿真模型建模详细步骤。 通过文档的形式&#xff0c;跟着文档一步一步操作&#xff0c;既可以提高自己的建模能力&#xff0c;又可以对整个建模思路进行借鉴&#xff0c;形成设计能力。 附带模型。纯电动汽车仿真模型在Simulink里搭建就像搭乐高——找准核心…

作者头像 李华
网站建设 2026/6/23 19:48:46

同花顺平衡多空看图操作多空理论

{}多空:50,COLORFFFFFF,POINTDOT; J:(C-LLV(L,9))/(HHV(H,9)-LLV(L,9))*100,colormagenta; K:SMA(J,3,1),colorwhite; D:SMA(K,3,1),coloryellow; 动能:100 * (LLV(LOW,60)-EMA(CLOSE,3))/(LLV(LOW,60)-HHV(HIGH,60)),colorligray,LINETHICK2; 多:IF(动能>多空,动能,DRAWNUL…

作者头像 李华
网站建设 2026/6/15 16:39:33

通达信222222测试帖别下载

{} Z1:STRCAT(【,STRCAT(CODE,STKNAME));Z2:STRCAT( 行业&#xff1a;,HYBLOCK);Z3:STRCAT( 地域&#xff1a;,DYBLOCK);Z4:STRCAT(STRCAT( 概念&#xff1a;,GNBLOCK),】);Z5:STRCAT(Z1,Z2);Z6:STRCAT(Z3,Z4);Z7:STRCAT(Z5,Z6);DRAWTEXT_FIX(1,0.35,0.030,0,Z7),COLORGREEN…

作者头像 李华
网站建设 2026/6/18 0:42:10

通达信大盘个股共振指标公式

{}个股:EMA(100*(C-LLV(LOW,34))/(HHV(H,34)-LLV(LOW,34)),3),COLOR1010FF; 大盘:EMA(100*(INDEXC-LLV(INDEXL,34))/(HHV(INDEXH,34)-LLV(INDEXL,34)),3),COLORE67010,LINETHICK2; STICKLINE(个股>大盘,个股,大盘,1,0),COLORRED; STICKLINE(个股<大盘,个股,大盘,1,0),COL…

作者头像 李华
网站建设 2026/6/23 4:56:20

这些核心特征,让芯片散料转编带设备成行业刚需

在电子制造业向自动化、高精度、规模化转型的过程中&#xff0c;芯片散料转编带设备之所以能成为行业刚需&#xff0c;不仅在于其强大的功能&#xff0c;更得益于一系列贴合行业需求的核心特征。这些特征既是设备技术实力的体现&#xff0c;也是企业提升生产效益的关键所在。高…

作者头像 李华