Spring boot 用idea打包成 war

Spring boot 用idea打包成 war

在pom中添加(添加之后程序无法启动)

  <!--打包需要的-->
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--End打包需要的-->

把之前的main换成

之前的mian

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class SpringBootSampleApplication/* extends SpringBootServletInitializer*/ {

	/*@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(SpringBootSampleApplication.class);
	}*/

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

现在的

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class SpringBootSampleApplication extends SpringBootServletInitializer {

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

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

然后BUild -> BUildArtifacts... -> 选中当前项目选中BUild 即可

posted @ 2017-11-11 09:09  猥琐熊花子酱  阅读(1745)  评论(1编辑  收藏  举报