springboot以war包方式运行的解决办法

1.编写启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BastApplication {

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

2.写一个类ServletInitializer继承SpringbootServletInitializer

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

public class ServletInitializer extends SpringBootServletInitializer {

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

}

3.更改pom.xml文件,将jar改为war

war

4.找到如下依赖并进行相应更改


            org.springframework.boot
            spring-boot-starter-tomcat
            
        

5.pom加入打包插件


        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    true
                
            
        
    
ok

你可能感兴趣的:(spring,boot)