Springboot 打war

pom 文件引入如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
Maven 打包的名字
<build>
    <finalName>springboot-vue</finalName>
</build>

修改springboot 启动类如下

@SpringBootApplication
@ServletComponentScan
public class SpringbootVueApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootVueApplication.class, args);
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot中,通常我们将应用程序打包成可执行的JAR文件,而不是WAR文件。但是,如果你确实需要将Spring Boot应用程序打包WAR文件,可以按照以下步骤进行操作: 1. 在你的Spring Boot项目的pom.xml文件中,将打包方式设置为war。在`<packaging>`元素中将值设置为war,如下所示: ```xml <packaging>war</packaging> ``` 2. 在你的主应用程序类上添加`extends SpringBootServletInitializer`,并重写`configure()`方法。这样可以将Spring Boot应用程序注册为一个Servlet。 ```java import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class YourApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(YourApplication.class); } // 程序的入口 public static void main(String[] args) { SpringApplication.run(YourApplication.class, args); } } ``` 3. 在pom.xml文件中添加servlet-api和jsp依赖。这些依赖项是为了支持WAR文件的部署和JSP页面的渲染。 ```xml <dependencies> <!-- 其他依赖 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>javax.servlet.jsp.jstl-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <!-- 其他依赖 --> </dependencies> ``` 4. 执行打包命令。在命令行中导航到你的项目根目录,并执行以下命令: ``` mvn clean package ``` 5. 在项目的`target`目录下将会生成一个WAR文件,你可以将该WAR文件部署到支持Java应用程序部署的Web服务器上。 希望以上步骤能帮助到你成功打包Spring Boot应用程序为WAR文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值