Spring Boot in Maven: No auto configuration classes found in META-INF/spring.factories
Solved. Rather than set intelliJ to make the .jar file as an artifact, I gave the command "./mvnw package -DskipTests" in the project directory in gitbash (a mentor gave me this advice). This built the project and the resulting jar file runs and works properly
No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct
make sure all dependencies downloaded successfully, then package your spring boot application from terminal command line:
mvn install
mvn clean package
Spring Boot - Gradle - No auto configuration classes found in META-INF/spring.factories
So i edited build.gradle like this and it is working now
/*
* 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'
}
No auto configuration classes found in META-INF/spring.factories error on running Spring Boot jar artifact
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.
Docker: image won't run : No auto configuration classes found in META-INF/spring.factories
This reminds me of a similar error I once had. The gradle build does only consider the source files you have in your project. It does not contain additional dependencies in the resulting jar file.
So this essentially means, that every dependency your project needs is not present.
To solve this you have to build an executable jar / fat jar.
Spring boot way
You can build an executable jar with the command ./gradlew bootJar
It is also possible to add the gradle configuration:
springBoot {
exectuable = true
}
Note: I do not have a lot of expierence regarding this config, but the documentation give a broader overview.
Shadow
You can also use a gradle plugin called shadow.
With it you can build an uber / fat jar which contains every dependency your app needs to run standalone.
Related Topics
What's the Correct Way to Send a File from Rest Web Service to Client
How to Set a Jlabel's Background Color
Resultset.Getstring(1) Throws Java.Sql.Sqlexception: Invalid Operation at Current Cursor Position
Registering Multiple Keystores in Jvm
Checking for a Null Int Value from a Java Resultset
Keylistener, Keypressed Versus Keytyped
Use of '? Extends ' and '? Super ' in Collection Generics
Dealing with Randomly Generated and Inconsistent JSON Field/Key Names Using Gson
How to Create a Project from Existing Source in Eclipse and Then Find It
How to Deserialize Js Date Using Jackson
Nextdouble() Throws an Inputmismatchexception When I Enter a Double
Calling Super Super Class Method
Can Spring Security Use @Preauthorize on Spring Controllers Methods
What Is the Purpose of the Java Constant Pool
Calling Win32 API Method from Java
Is This the Best Way to Rewrite the Content of a File in Java