Spring 启动 - Gradle - 在 META-INF/spring.factories 中未找到自动配置 类
Spring Boot - Gradle - No auto configuration classes found in META-INF/spring.factories
当我在 idea 中启动应用程序时它运行良好但是当我尝试从 cmd 启动这个应用程序时 java -jar build/libs/dev-0.0.1-SNAPSHOT.jar
我收到这个错误
21:02:06.634 [main] 错误 org.springframework.boot.SpringApplication - 应用程序 运行 失败
java.lang.IllegalArgumentException:META-INF/spring.factories 中未找到自动配置 类。如果您使用自定义包装,请确保文件正确。
这是我的build.gradle
/*
* This file was generated by the Gradle 'init' task.
*/
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.6.7"
}
}
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
implementation 'org.springframework:spring-aop:5.3.19'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
implementation 'org.flywaydb:flyway-core:8.5.10'
runtimeOnly 'org.postgresql:postgresql:42.3.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
testImplementation 'org.springframework.security:spring-security-test:5.6.3'
testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
testImplementation 'org.testcontainers:spock:1.17.1'
testImplementation "org.testcontainers:postgresql:1.17.1"
}
group = 'com.dev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
java.sourceCompatibility = JavaVersion.VERSION_17
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
compileJava {
options.compilerArgs += "-Amapstruct.defaultComponentModel=spring"
options.compilerArgs += "-Amapstruct.unmappedTargetPolicy=WARN"
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
'Main-Class': 'com.dev.DevApplication',
'Class-Path': configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(' ')
)
}
from{
configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it)}
}
}
所以我像这样编辑了build.gradle,现在可以使用了
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
id 'org.springframework.boot' version '2.6.7'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
implementation 'org.springframework:spring-aop:5.3.19'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
implementation 'org.flywaydb:flyway-core:8.5.10'
runtimeOnly 'org.postgresql:postgresql:42.3.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
testImplementation 'org.springframework.security:spring-security-test:5.6.3'
testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
testImplementation 'org.testcontainers:spock:1.17.1'
testImplementation "org.testcontainers:postgresql:1.17.1"
}
group = 'com.dev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
compileJava {
options.compilerArgs += "-Amapstruct.defaultComponentModel=spring"
options.compilerArgs += "-Amapstruct.unmappedTargetPolicy=WARN"
}
jar {
enabled = false
}
springBoot {
mainClass = 'com.dev.DevApplication'
}
当我在 idea 中启动应用程序时它运行良好但是当我尝试从 cmd 启动这个应用程序时 java -jar build/libs/dev-0.0.1-SNAPSHOT.jar
我收到这个错误
21:02:06.634 [main] 错误 org.springframework.boot.SpringApplication - 应用程序 运行 失败 java.lang.IllegalArgumentException:META-INF/spring.factories 中未找到自动配置 类。如果您使用自定义包装,请确保文件正确。
这是我的build.gradle
/*
* This file was generated by the Gradle 'init' task.
*/
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.6.7"
}
}
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
implementation 'org.springframework:spring-aop:5.3.19'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
implementation 'org.flywaydb:flyway-core:8.5.10'
runtimeOnly 'org.postgresql:postgresql:42.3.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
testImplementation 'org.springframework.security:spring-security-test:5.6.3'
testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
testImplementation 'org.testcontainers:spock:1.17.1'
testImplementation "org.testcontainers:postgresql:1.17.1"
}
group = 'com.dev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
java.sourceCompatibility = JavaVersion.VERSION_17
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
compileJava {
options.compilerArgs += "-Amapstruct.defaultComponentModel=spring"
options.compilerArgs += "-Amapstruct.unmappedTargetPolicy=WARN"
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
'Main-Class': 'com.dev.DevApplication',
'Class-Path': configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(' ')
)
}
from{
configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it)}
}
}
所以我像这样编辑了build.gradle,现在可以使用了
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
id 'org.springframework.boot' version '2.6.7'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-security:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.6.7'
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.7'
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.6.7'
implementation 'org.springframework:spring-aop:5.3.19'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.vladmihalcea:hibernate-types-52:2.16.2'
implementation 'org.flywaydb:flyway-core:8.5.10'
runtimeOnly 'org.postgresql:postgresql:42.3.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.7'
testImplementation 'org.springframework.security:spring-security-test:5.6.3'
testImplementation 'org.codehaus.groovy:groovy-all:3.0.10'
testImplementation 'org.spockframework:spock-core:2.1-groovy-3.0'
testImplementation 'org.spockframework:spock-spring:2.1-groovy-3.0'
testImplementation 'org.testcontainers:spock:1.17.1'
testImplementation "org.testcontainers:postgresql:1.17.1"
}
group = 'com.dev'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
targetCompatibility = '17'
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
compileJava {
options.compilerArgs += "-Amapstruct.defaultComponentModel=spring"
options.compilerArgs += "-Amapstruct.unmappedTargetPolicy=WARN"
}
jar {
enabled = false
}
springBoot {
mainClass = 'com.dev.DevApplication'
}