Skip to content
Advertisement

“No auto configuration classes found in META-INF/spring.factories” error on running Spring Boot jar artifact

I use openjdk 14.0.2, Gradle 7.1.1 and IntelliJ IDEA 2021.1.2. I have a Spring Boot project and can run it successfully. Now I want to create an executable jar file. This is build.gradle:

plugins {
    id 'org.springframework.boot' version '2.5.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'mysql:mysql-connector-java'
    annotationProcessor 'org.projectlombok:lombok'
}

I built main.jar artifact like it is described here; but executing this command:

$ java -jar main.jar 

causes this error:

ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.

For solving the problem I tried what is described here by adding

bootJar {
    mainClassName = 'com.example.ExampleApplication'
}

to the build.gradle; but the problem is remained.

Note:

  • I do not want to use Maven instead of Gradle.

Advertisement

Answer

In stead of trying to combine jar creation with intellij and gradle, just use gradle: First run ./gradlew assemble or ./gradlew build (if you want to also run tests and checks) the spring boot gradle plugin will create a fat jar for you which you can run with the java -jar command. It will be in the ./build/libs folder.

edit: you can ofcourse also use intellij to run these gradle tasks if you prefer.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement