Spring-boot – Using Gradle-No auto configuration classes found in META-INF/spring.factories

gradleintellij-ideaspring-boot

Trying to deploy a jar I build using the jar function in gradle in IntelliJ on my spring boot.It runs fine locally from my IDE using "bootrun" but not putting a jar on a linux server.Full error on the server is

Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [haughton.icecreamapi.config.AppConfig]; nested exception is 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.

My build.gradle

group 'IceCreamApiCA1'
version '1.0-SNAPSHOT'
buildscript {

ext {
    springBootVersion = '1.5.9.RELEASE'
}
repositories{
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-
 plugin:${springBootVersion}")    }
 }

 // Apply the Spring Boot plugin
 //apply plugin: 'spring-boot'
 apply plugin: 'org.springframework.boot'
 // Apply the Java plugin (expects src/main/java to be source folder)
 apply plugin: 'java'

  // Specify the location where our dependencies will be found
repositories {
mavenCentral()
maven {
    url "http://repo.spring.io/milestone/"
}
}
jar{
baseName='IceCreamRestApi'
version='1.0.0'
manifest{
    attributes 'Main-Class': 'haughton.icecreamapi.Application'
}
from{
    configurations.compile.collect{ it.isDirectory() ? it : zipTree(it)}
}
}

 // Specify dependencies
dependencies {
compile 'org.hashids:hashids:1.0.1'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.2.RELEASE'

compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework:spring-orm:4.3.7.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-jdbc
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-context

compile 'org.apache.tomcat:tomcat-dbcp:8.0.30'

//compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity:3.0.2.RELEASE'
// https://mvnrepository.com/artifact/com.google.code.gson/gson
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
 // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'

// https://mvnrepository.com/artifact/com.h2database/h2
compile group: 'com.h2database', name: 'h2', version: '1.4.196'

runtime 'javax.transaction:jta:1.1'
runtime 'org.aspectj:aspectjweaver:1.8.7'


 // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
 compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
 testCompile 'org.springframework.boot:spring-boot-starter-test'

 }

Best Answer

I think you should let spring-boot plugin to create executable jar (don't write it your self). By default this plugin will search for public static void main(String[]) method in directories on the task’s classpath. If you want to specify yourself use bootJar task.

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

https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/gradle-plugin/reference/html/

Related Topic