【发布时间】:2017-05-12 09:16:54
【问题描述】:
我已经通过 Intellij 创建了 spring-boot Web 项目,并且在通过 SpringApplication.run() 方法构建或启动项目后在任何地方都看不到我的 Web 存档。在文档页面上,我发现了三个应遵守的条款
- 生成可部署的 war 文件的第一步是提供 SpringBootServletInitializer
- 将战争插件应用到项目中
- 确保嵌入式 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')
}
【问题讨论】:
-
我可以使用 IntelliJ 2016 和 Maven 创建一个 WAR。我现在没有代码在我面前。我会试着找到它。我没有看到我认为你需要的插件。你能在 Gradle 设置中突出显示它吗?
-
我不确定 graille 但使用 maven 你可以运行 mvn package 并在 /target 文件夹中生成一个 WAR 文件
-
运行应用程序当然不会引发战争。您必须在命令行(或在 IntelliJ 中)使用
gradle build来创建工件。运行应用程序,顾名思义,就是运行应用程序。
标签: java spring-boot build.gradle