当前位置 主页 > 服务器问题 > Linux/apache问题 >

    如何把springboot jar项目 改为war项目

    栏目:Linux/apache问题 时间:2019-11-16 16:24

    这篇文章主要介绍了如何把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>

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持IIS7站长之家。