gpt4 book ai didi

java - 使用 ./gradlew appRun 运行 Spring Boot 应用程序

转载 作者:行者123 更新时间:2023-12-02 10:34:08 25 4
gpt4 key购买 nike

我个人选择在学校项目中使用 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类似或直接./gradlew bootRun启动SpringBoot主类?

最佳答案

这是一个很奇怪的问题。将此行添加到 gretty 配置中:

gretty {
contextPath = '/'
springBoot = true
}

这是文档:http://akhikhl.github.io/gretty-doc/spring-boot-support.html

关于java - 使用 ./gradlew appRun 运行 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53419391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com