• 先指定jsp目录,右键项目选择properties(注意的是第三步,如果之前选中第二步的话,要去掉,apply之后再选中才会出现第三步)

Springboot集成jsp

Springboot集成jsp

 

第二步.pom.xml调整

2.1 打包方式修改

<packaging>jar</packaging>

变更为

<packaging>war</packaging>

2.2. 添加依赖

重点:scope是provided

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-tomcat</artifactId>

    <scope>provided</scope>

</dependency>

2.3. 排除嵌入式tomcat

不排除也没影响,多个jar而已

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-web</artifactId>

    <exclusions>

        <exclusion>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

        </exclusion>

    </exclusions>

</dependency>

2.4. 注释spring-boot-maven-plugin,使用maven-war-plugin

<!--

<plugin>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-maven-plugin</artifactId>

    <configuration>

        <mainClass>bing.AuthorityApplication</mainClass>

        <layout>ZIP</layout>

    </configuration>

    <executions>

        <execution>

            <goals>

                <goal>repackage</goal>

            </goals>

        </execution>

    </executions>

</plugin> -->

 

<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-war-plugin</artifactId>

    <configuration>

           <failOnMissingWebXml>false</failOnMissingWebXml>

    </configuration>

</plugin>

 

第三.启动类修改

继承SpringBootServletInitializer覆盖configure方法,示例:

 

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 Application extends SpringBootServletInitializer{

 

@Override

protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {

return builder.sources(Application.class);

}

 

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

 

第四. 省略项目名部署方法

修改TOMCAT的server.xml,demo是项目文件夹(将path值清空就可以了)

 

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

    ...

    

    <Context path="" docBase="D:/opt/demo" debug="0" reloadable="true"/>

    ...

</Host>

相关文章: