java - 使用 ./gradlew appRun 运行 Spring Boot 应用程序
问题描述
我将 Spring Boot 用于学校项目作为个人选择,但自动测试仪用于./gradlew appRun
启动整个过程。
在他们使用 servlet 之前这很好,但是在迁移到 Spring Boot 之后,我在尝试这样做时遇到了几个异常。
Execution failed for task ':appRun'.
Could not get unknown property 'mainClass' for object of type org.springframework.boot.gradle.dsl.SpringBootExtension.
这是我目前的build.gradle
.
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath "gradle.plugin.org.akhikhl.gretty:gretty:2.0.0"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'org.gretty' version '2.2.0'
id 'war'
}
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "org.akhikhl.gretty"
apply plugin: 'application'
sourceCompatibility = 8
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('com.h2database:h2')
runtimeOnly('mysql:mysql-connector-java')
runtimeOnly('org.hsqldb:hsqldb')
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.7'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.apache.ibatis', name: 'ibatis-core', version: '3.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'
compile group: 'org.apache.ibatis', name: 'ibatis-core', version: '3.0'
compile group: 'org.gretty', name: 'gretty-runner-jetty94', version: '2.2.0'
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')
runtimeOnly('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
gretty {
contextPath = '/'
}
这一切在使用时都可以正常工作,./gradlew bootRun
但没有通过自动化测试仪。
有没有办法让运行./gradlew appRun
启动SpringBoot主类类似或直接./gradlew bootRun
?
解决方案
这是一个很好的问题。将此行添加到 gretty 配置中:
gretty {
contextPath = '/'
springBoot = true
}
这是文档:http ://akhikhl.github.io/gretty-doc/spring-boot-support.html
推荐阅读
- matrix - SSRS 报告的两个问题(行号、行大小)
- javascript - 从 Javascript 发送 QueryDict 对象(没有表单?)
- matplotlib - 如何“缩放”到 osmnx 图中的特定区域
- python - 消除python中除字母以外的输入文本
- r-markdown - 当尝试将 kableExtra::kable 与 as_image() 一起使用时,Rmarkdown 出现问题,以在 Word 中生成表格
- python - 删除短输入功能中的冗余行
- uwp - MSIX 打包工具:从 x86 到 x64 的应用
- python - 在 multiprocessing.Pool.apply_async 函数中使用 multiprocessing.Pipe() 时发生死锁
- html - 如何在具有溢出滚动的父项中包含子元素的边距?
- android - 获取“未找到证书路径的信任锚”。对于曾经有效的服务