zoukankan      html  css  js  c++  java
  • 【SpringBoot】Warの作成

    ①pom.xml(WARの設定)

      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <project xmlns="http://maven.apache.org/POM/4.0.0"
      3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      4     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
      5     <modelVersion>4.0.0</modelVersion>
      6 
      7     <parent>
      8         <groupId>org.springframework.boot</groupId>
      9         <artifactId>spring-boot-starter-parent</artifactId>
     10         <version>2.2.6.RELEASE</version>
     11         <relativePath /> <!-- lookup parent from repository -->
     12     </parent>
     13     <groupId>com.example</groupId>
     14     <artifactId>warapp</artifactId>
     15     <version>0.0.1-SNAPSHOT</version>
     16     <packaging>war</packaging>
     17     <name>War</name>
     18     <description>Demo War Project  For Spring Boot</description>
     19 
     20     <properties>
     21         <java.version>1.8</java.version>
     22     </properties>
     23 
     24     <dependencies>
     25 
     26         <dependency>
     27             <groupId>org.springframework.boot</groupId>
     28             <artifactId>spring-boot-starter-thymeleaf</artifactId>
     29         </dependency>
     30         <dependency>
     31             <groupId>org.springframework.boot</groupId>
     32             <artifactId>spring-boot-starter-web</artifactId>
     33             <!-- 追加↓↓↓↓↓↓ -->
     34             <exclusions>
     35                 <exclusion>
     36                     <groupId>org.springframework.boot</groupId>
     37                     <artifactId>spring-boot-starter-tomcat</artifactId>
     38                 </exclusion>
     39             </exclusions>
     40             <!-- 追加↑↑↑↑↑↑ -->
     41         </dependency>
     42         <dependency>
     43             <groupId>org.springframework.boot</groupId>
     44             <artifactId>spring-boot-starter-web-services</artifactId>
     45         </dependency>
     46 
     47         <dependency>
     48             <groupId>org.springframework.boot</groupId>
     49             <artifactId>spring-boot-devtools</artifactId>
     50             <scope>runtime</scope>
     51             <optional>true</optional>
     52         </dependency>
     53         <dependency>
     54             <groupId>com.h2database</groupId>
     55             <artifactId>h2</artifactId>
     56             <scope>runtime</scope>
     57         </dependency>
     58         <dependency>
     59             <groupId>org.springframework.boot</groupId>
     60             <artifactId>spring-boot-configuration-processor</artifactId>
     61             <optional>true</optional>
     62         </dependency>
     63         <dependency>
     64             <groupId>org.projectlombok</groupId>
     65             <artifactId>lombok</artifactId>
     66             <optional>true</optional>
     67         </dependency>
     68         <dependency>
     69             <groupId>org.springframework.boot</groupId>
     70             <artifactId>spring-boot-starter-tomcat</artifactId>
     71             <scope>provided</scope>
     72         </dependency>
     73         <dependency>
     74             <groupId>org.springframework.boot</groupId>
     75             <artifactId>spring-boot-starter-test</artifactId>
     76             <scope>test</scope>
     77             <exclusions>
     78                 <exclusion>
     79                     <groupId>org.junit.vintage</groupId>
     80                     <artifactId>junit-vintage-engine</artifactId>
     81                 </exclusion>
     82             </exclusions>
     83         </dependency>
     84 
     85         <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
     86         <!-- 追加↓↓↓↓↓↓ -->
     87         <dependency>
     88             <groupId>javax.servlet</groupId>
     89             <artifactId>javax.servlet-api</artifactId>
     90             <scope>provided</scope>
     91         </dependency>
     92         <!-- 追加↑↑↑↑↑↑ -->
     93         <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
     94         <!-- <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> 
     95             <version>9.0.34</version> </dependency> -->
     96 
     97     </dependencies>
     98 
     99     <build>
    100         <!-- 追加(War起動用Context)↓↓↓↓↓↓ -->
    101         <finalName>warapp</finalName>
    102         <!-- 追加(War起動用Context)↑↑↑↑↑↑ -->
    103         <plugins>
    104             <plugin>
    105                 <groupId>org.springframework.boot</groupId>
    106                 <artifactId>spring-boot-maven-plugin</artifactId>
    107             </plugin>
    108         </plugins>
    109     </build>
    110 </project>
    View Code

    ②application.properties(SpringBootの起動用の設定)

    #Springboot Start Config
    server.port=8088
    server.servlet.context-path=/demoapp
    View Code

    方法一:WarApplication.javaのSpringBootServletInitializerをExtendsする

     1 package com.example.app;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.SpringBootApplication;
     5 import org.springframework.boot.builder.SpringApplicationBuilder;
     6 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
     7 
     8 @SpringBootApplication
     9 public class WarApplication extends SpringBootServletInitializer{
    10 
    11     public static void main(String[] args) {
    12         SpringApplication.run(WarApplication.class, args);
    13     }
    14 
    15     @Override
    16     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    17         return application.sources(WarApplication.class);
    18     }
    19 }
    View Code

    方法二:ServletInitializerの新規

     1 package com.example.app;
     2 
     3 import org.springframework.boot.builder.SpringApplicationBuilder;
     4 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
     5 
     6 public class ServletInitializer extends SpringBootServletInitializer {
     7 
     8     @Override
     9     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    10         return application.sources(WarApplication.class);
    11     }
    12 
    13 }
    View Code

    ④その他

    https://qiita.com/yuji38kwmt/items/84927f21c71a163724f1

    https://www.jianshu.com/p/e4a9ac255be3

  • 相关阅读:
    November 13th 2016 Week 47th Sunday The 1st Day
    November 12th 2016 Week 46th Saturday
    November 11th 2016 Week 46th Friday
    November 10th 2016 Week 46th Thursday
    November 9th 2016 Week 46th Wednesday
    November 8th 2016 Week 46th Tuesday
    windows 7文件共享方法
    Win7无线网络共享设置方法
    常量指针和指针常量
    如何查找局域网的外网ip
  • 原文地址:https://www.cnblogs.com/lnsylt/p/12724934.html
Copyright © 2011-2022 走看看