xiongyingaoxiang

第一步修改pom文件:

1.1打成war文件

<packaging>war</packaging>

  

 

 

1.2排除内置tomcat插件:

 

<exclusions>
        <exclusion>
              <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
</exclusions>

1.3 加servlet-api的依赖

有两种方法:  我两种方法都试过

第一种

<dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>9.0.35</version>
        <scope>provided</scope>
</dependency>

备注: 我用的tomcat版本对应: 9.0.35

第二种

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
</dependency>

1.4定义项目打包名字和打包拷贝静态文件

定义项目打包名:

<finalName>happywarname</finalName>

 

 

 打包拷贝静态文件(jsp页面,css,js等):

<resources>
    <resource>
        <directory>src/main/webapp</directory>                        
        <targetPath>METAINF/resources</targetPath>
        <includes>
                    <include>**/**</include>
        </includes>
    </resource>
    <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
    </resource>
</resources>

第二步:重写启动类的初始化方法

SpringbootJspApplication 启动类
@SpringBootApplication
public class SpringbootJspApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootJspApplication.class, args);
    }
    
}
ServletInitializer类 继承SpringBootServletInitializer类重写configure方法
package com.springbootjsp;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringbootJspApplication.class);
    }

}

 

第三步用Maven打包:

点击项目右击1.1:  run as —>Maven clean

 

 

1.2 项目右击Maven ——>Update Project——>OK

点击项目右击1.3:  run as —>Maven Build

 

Goals 填写 pagckage,然后勾选Skip Tests

配置jre

有两种

第二种配置方法如下

第四步:run(打包)

 

 

 打包成功后:

打的war包在target目录下

 

第五步将war包放(复制粘贴)在tomcat的webapp文件夹下:

然后更改tomcat conf下server.xml文件

<!-- 修改Tomcat默认访问路径  -->
<Context path=""  docBase="/happywarname" reloadable="true" />

最后启动(双击)tomcat  bin目录下的startup.bat

 

tomcat 启动:

访问rest接口或页面:

分类:

技术点:

相关文章:

  • 2021-08-30
  • 2019-01-06
  • 2021-11-18
  • 2022-12-23
  • 2021-10-12
  • 2022-01-15
  • 2022-12-23
  • 2021-05-25
猜你喜欢
  • 2019-12-07
  • 2021-07-01
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案