Spring boot project is failing on run and giving below errors. What is causing this error and How can i prevent.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/z00381z/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.11.1/4b41b53a3a2d299ce381a69d165381ca19f62912/log4j-slf4j-impl-2.11.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/z00381z/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.11/ccedfbacef4a6515d2983e3f89ed753d5d4fb665/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Gradle File
buildscript {
repositories {
maven { url "https://binrepo.mycompany.com/artifactory/platform" }
maven { url "https://binrepo.mycompany.com/artifactory/maven-central" }
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.mycompany.platform:platform-connector-gradle:1.1.4"
}
}
apply plugin: 'org.springframework.boot'
apply plugin: "com.mycompany.platform.connector.spring-boot"
apply plugin: "io.spring.dependency-management"
mainClassName = "com.mycompany.learnattargetuser.Main"
version = "0.0.1"
distTar.version = ""
dependencies{
compile "org.springframework.boot:spring-boot-starter-data-jpa"
}
Noticed that the conflict comes from two jars, named logback.jar and log4j-slf4j-impl-.jar.
Now choose the one you want to ignore.
I'll ignore slf4j-log4j12.
In gardle
configurations.all {
exclude module: 'slf4j-log4j12'
}
or ignore logback.
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
Related
Our application is currently running on spring boot 1.5.10.RELEASE version, and I'm trying to upgrade to spring boot 2.0.0.RELEASE But after upgrading to 2.0.0.RELEASE I get the following error
Error: Could not find or load main class com.app.MyApplication
Given Below is the build.gradle file
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
camelVersion = '2.24.0'
}
repositories {
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
apply from: '../common.gradle'
apply from: '../test.gradle'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'io.spring.dependency-management'
dependencies {
providedRuntime "org.springframework.boot:spring-boot-starter-tomcat"
compile ("org.flywaydb:flyway-core:5.0.7")
compile ("org.springframework.retry:spring-retry:1.2.2.RELEASE")
compile("org.springframework:spring-jms:5.1.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-activemq:2.0.6.RELEASE")
compile("org.springframework:spring-jdbc:5.0.4.RELEASE")
compile("org.springframework.retry:spring-retry:1.2.2.RELEASE")
compile("com.amazonaws:aws-java-sdk-sqs:1.11.428")
compile("com.amazonaws:amazon-sqs-java-messaging-lib:1.0.4")
compile ("org.flywaydb:flyway-core:5.0.7")
runtime("org.apache.activemq:activemq-kahadb-store:5.15.6")
compile("org.apache.camel:camel-spring-boot-starter:${camelVersion}")
compile("org.apache.camel:camel-core:${camelVersion}")
compile("org.apache.camel:camel-http-starter:${camelVersion}")
compile("org.apache.camel:camel-http4:${camelVersion}")
compile("org.apache.camel:camel-jsonpath:${camelVersion}")
compile("org.apache.camel:camel-jackson:${camelVersion}")
compile("org.apache.camel:camel-base64:${camelVersion}")
compile("org.apache.camel:camel-groovy:${camelVersion}")
compile("org.apache.camel:camel-jolt:${camelVersion}")
compile("org.apache.camel:camel-jaxb:${camelVersion}")
compile("org.apache.camel:camel-ahc:${camelVersion}")
compile("org.codehaus.groovy:groovy-json:3.0.3")
}
configurations {
all*.exclude group: '', module: 'servlet-api'
}
springBoot {
mainClassName = 'com.app.MyApplication'
}
war {
archiveName = "application.war"
}
I'm wondering if this is due to the camel dependencies as when I tried to use Spring Boot version 1.5.22. It is working fine but as soon as I change this to 2.x.x it stop working.
This issue got resolved when I ran this application in Intellij instead of the eclipse.
I am starting on Spring and learning its foundations. I created a project in intellij
It was giving an error stating that web cannot be imported.
so i guessed it must have been . my gradle build file which does not have web
I tried to import in manually via the build.gradle file as below but it throws me an error saying it cannot be found.
WHat am i doing wrong and how can i resolve this?
plugins {
id 'org.springframework.boot' version '2.2.2.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'io.codementor.gtommee'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
any help?
You are missing the spring-boot-starter-web dependency in your build.gradle file.
To get started, have a look at https://start.spring.io/
I have the following build.gradle:
group 'as'
version '1.0'
buildscript {
ext {
springVersion = '5.0.4.RELEASE'
springBootVersion = '1.5.6.RELEASE'
springJPAVersion = '2.0.5.RELEASE'
javaxVersion = '1.0.2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'reports'
version = '0.0.1'
manifest {
attributes 'Implementation-Title': baseName,
'Implementation-Version': version
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
implementation "org.springframework.data:spring-data-jpa:${springJPAVersion}"
implementation "javax.persistence:persistence-api:${javaxVersion}"
implementation "mysql:mysql-connector-java:5.1.43"
testImplementation group: 'junit', name: 'junit', version: '4.11'
}
And gradle creates jar with following structure:
BOOT-INF
classes
META-INF
org
But it seems that the structure must be the following:
BOOT-INF
classes
lib
META-INF
org
with lib folder, which contains dependencies, because now after launch I get error:
Exception ...
Caused by: java.lang.NoClassDefFoundError:
org/springframework/boot/SpringApplication at com.as.reports.Application.main(Application.java:12)
So I know this answer is probably too late to help you, but I stumbled across this question while trying to solve the exact same problem, and was reminded of this.
After half a day of trial and error, I found the solution, so hopefully I can save someone else the pain of finding this unanswered question.
The problem is with using the implementation keyword in your dependencies. The 1.x Spring Boot Gradle plugin doesn't appear recognize that keyword as notating required dependencies for repackaging a fat jar. If you change those back to the older compile keyword, you should get the necessary lib folder.
Hi,
Below exception is thrown when I include ignite dependency with my spring boot app. Even though reason seems obvious that 2 jars are in deadlock here, can you suggest me how can I fix this. I am not adding any of these jars directly and these are included automatically with other dependencies.
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
classpath 'mysql:mysql-connector-java:5.1.34'
}
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
// In this section you declare the dependencies for your production and test code
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java:5.1.34")
// Ignite dependencies
compile group: 'org.apache.ignite', name: 'ignite-core', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-spring', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-indexing', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-rest-http', version: '1.6.0'
testCompile 'junit:junit:4.12'
}
Exception:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.21/7238b064d1aba20da2ac03217d700d91e02460fa/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.7/9865cf6994f9ff13fce0bf93f2054ef6c65bb462/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.boot.App.<clinit>(App.java:42)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
You have to exclude conflicting dependencies, like below.
Refer official documentation for more info.
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
Example from the official documentation:
Replacing a persistence layer in legacy app with a JAR file using Spring, Hibernate and GORM. Methods like person.save() work fine when running agains project with Gradle etc. in project. However, after I build the fat jar and reference it with -cp my-big-fat-gorm.jar I get:
java.lang.IllegalStateException: Method on class [blah.Person] was
used outside of a Grails application. If running in the context of a
test using the mocking API or bootstrap Grails correctly.
Using Spring boot for Spring, Hibernate4 and GORM and build.gradle file show below...
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'application'
mainClassName = "blah.App"
jar {
baseName = 'blah-gorm'
version = '1.0-SNAPSHOT'
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.8.2'
compile 'org.grails:gorm-hibernate4-spring-boot:1.1.0.RELEASE'
compile 'org.slf4j:slf4j-simple:1.7.7'
runtime 'com.h2database:h2:1.4.181'
}
Am I missing something in the JAR file creation that causes Spring boot to honor #Entity etc.?
Here is a GitHub project that illustrates this and should allow you to execute and see the same stuff I'm seeing.
https://github.com/twcrone/spring-gorm-jar
You don't have the Spring Boot Gradle plugin installed so you're not actually creating a fat JAR you need to add the following to your build.gradle file:
apply plugin: 'spring-boot'
buildscript {
ext {
springBootVersion = '1.1.0.M2'
groovyVersion = '2.3.2'
}
repositories {
mavenCentral()
maven {
url 'http://repo.spring.io/milestone'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
With this in place doing gradle assemble and then java -jar ... results in bootstrapping GORM correctly