无法为 Spring 引导 Web 项目创建战争存档



我已经通过Intellij创建了spring-boot web项目,并且在通过SpringApplication.run((方法构建或启动项目后无法在任何地方看到我的Web存档。在文档页面上,我发现了三个应该遵守的条款

  1. 生成可部署战争文件的第一步是提供一个 SpringBootServletInitializer
  2. 将战争插件应用于项目
  3. 确保嵌入式 servlet 容器不会干扰将部署 war 文件的 servlet 容器,方法是添加 providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'构建脚本

我的 servlet 初始值设定项

public class ServletInitializer extends SpringBootServletInitializer {    
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(RegTemplateApplication.class);
        }
    }

我的构建脚本

buildscript {
    ext {
        springBootVersion = '1.5.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}
configurations {
    providedRuntime
}
dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('com.h2database:h2')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

要组装战争,你应该跑gradle assemble

默认情况下,此命令将从src/main/webapp源创建战争神器。还要检查您的来源是否在该目录中,或者您应该提供webAppDirName属性

见 https://docs.gradle.org/current/userguide/war_plugin.html

我尝试使用以下方法构建:

gradle clean build

并在此目录中找到了网络存档:

./build/libs/build.war

注意:您必须在计算机上安装 gradle。

最新更新