一、pom.xml中加入打包插件
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
二、启动类的写法
package com.example.springbootweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@ServletComponentScan
public class SpringbootWebApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SpringbootWebApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootWebApplication.class);
}
}
需要继承SpringBootServletInitializer类并重写SpringApplicationBuilder方法
三、在idea中打包
打包后发布,注意访问路径为http://localhost:8080/springboot-web/helloJsp,要注意在tomcat中的webapp中的有关目录名称对应的工程的上下文。工程已上传,地址为打包工程