SpringBoot项目打成war包部署到Tomcat

修改pom.xml文件

添加Tomcat依赖包

	<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-tomcatartifactId>
			<scope>providedscope>
		dependency>

把pakaging有jar改成war

	
	<packaging>warpackaging>

重写SpringBootServletInitializer的configure方法

与Application类在一个目录下

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

也可以直接修改启动类

@SpringBootApplication
public class Application extends SpringBootServletInitializer{
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }


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

然后打包
SpringBoot项目打成war包部署到Tomcat_第1张图片

注:有时候测试方法法出错、使用断言抛出异常会导致打成war包失败
或者不想执行测试类
解决方法为修改pom.xml文件

<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-surefire-pluginartifactId>
				<configuration>
					<testFailureIgnore>truetestFailureIgnore>
				configuration>
			plugin>
		plugins>
build>

你可能感兴趣的:(springboot)