1. 程式人生 > 程式設計 >如何把springboot jar專案 改為war專案

如何把springboot jar專案 改為war專案

這篇文章主要介紹瞭如何把springboot jar專案 改為war專案,文中通過示例程式碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

啟動類JeewxBootApplication 新增繼承SpringBootServletInitializer

重寫實現

@SpringBootApplication
public class JeewxBootApplication extends SpringBootServletInitializer {
  public final static Logger log = LoggerFactory.getLogger(JeewxBootApplication.class);

  public static void main(String[] args) {
    ConfigurableApplicationContext application = SpringApplication.run(JeewxBootApplication.class,args);
    Environment env = application.getEnvironment();
    String ip = InetAddress.getLocalHost().getHostAddress();
    String port = env.getProperty("server.port");
    String path = env.getProperty("server.servlet.context-path");
    log.info("\n----------------------------------------------------------\n\t" +
      "Application is running! Access URLs:\n\t" +
      "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
      "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
      "----------------------------------------------------------");
  }

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

}

pom檔案新增外掛

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </configuration>
</plugin>

pom檔案新增依賴

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。