SLF4J AND LOG4J binding exception in spring boot app with ignite dependency - spring-boot

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:

Related

Cannot resolve external dependency org.springframework.boot:spring-boot-starter-web:3.0.0

I was trying to create a simple spring boot project with single module and the repository was
mavenCentral(). the dependency I have used in project were literally taken from maven central. I dont understand why its not working, it had worked before.
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '3.0.0'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
this is my buid.gradle.
test: Could not resolve org.springframework.boot:spring-boot-starter-web:3.0.0.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
this is the error I am getting

Repositories in gradle project were not indexed

I'm trying to synchronize a gradle project with some dependences to Spring Boot and Maven, but there is an error that indicates the following repositories used in the project are not indexed yet:
Unindexed remote maven repositories found.
The following repositories used in your gradle projects were not
indexed yet:
http://repo.spring.io/milestone
http://repo.spring.io/snapshot
https://repo1.maven.org/maven2
https://plugins.gradle.org/m2
If you want to use dependency completion for these repositories
artifacts, Open Repositories List, select required repositories and press "Update" button.
Then I'm trying to update the remote repositories manually, but I'm getting an error while I trying to do.
Any know what can I do to resolve the issue?
I'm using IntelliJ IDEA 2017.1.6 and the gradle version is 2.2, I leave the build.gradle file of the project with the dependencies that I use.
group 'com.scl.boot'
version '0.5'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'spring-boot'
apply plugin: 'org.sonarqube'
apply plugin: 'com.bmuschko.cargo'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
buildscript {
repositories {
jcenter()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE'
classpath 'org.sonarqube.gradle:gradle-sonarqube-plugin:1.1'
classpath 'com.bmuschko:gradle-cargo-plugin:2.2.1'
}
}
repositories {
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
mavenCentral()
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-aop'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'org.springframework.boot:spring-boot-starter-security'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '1.3.6.RELEASE'
compile 'org.jsondoc:spring-boot-starter-jsondoc:1.2.9'
compile 'org.jsondoc:jsondoc-ui-webjar:1.2.9'
compile 'org.springframework:spring-jdbc'
compile 'org.springframework.data:spring-data-oracle:1.2.1.RELEASE'
compile group: 'cn.easyproject', name: 'ojdbc7', version: '12.1.0.2.0'
compile group: 'org.springframework.data', name: 'spring-data-jdbc-core', version: '1.2.1.RELEASE'
compile 'org.apache.tomcat:tomcat-dbcp:8.0.28'
compile 'org.slf4j:slf4j-api:1.7.+'
compile 'org.op4j:op4j-jodatime:1.1'
compile 'org.springframework.boot:spring-boot-devtools:1.3.0.M2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile 'org.json:json:20151123'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.codehaus.groovy:groovy-all'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.3'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.3'
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.8.3'
cargo 'org.jboss.as:jboss-as-controller-client:7.2.0.Final'
compile group: 'org.codehaus.cargo', name: 'cargo-core-uberjar', version: '1.5.0'
cargo 'org.codehaus.cargo:cargo-ant:1.4.16'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.springframework.boot:spring-boot-starter-test:1.2.7.RELEASE'
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
}
war {
archiveName = "CyCRest.war"
configurations {
runtime.exclude module: 'spring-boot-starter-tomcat'
runtime.exclude module: 'spring-boot-starter-logging'
}
}
[EDIT] This is the idea.log file with the exceptions that I'm getting:
java.io.IOException: Transfer for nexus-maven-repository-index.gz
failed
Download the log file.

Gradle spring-boot error - java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication

Below is my build.gradle file. I am using java 11 and IntelliJ 2019.2.2. As I run the application, I get: Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
As such the error or problem appears to be the same as the one you get when you upgrade from gradle version 2.x to anything 3.4 onwards, but I should not be getting the error with any recent IntelliJ version. I have cleaned the repository, idea cache etc. The main class (com.itreatmd.emr.Application) has only one line - SpringApplication.run(Application.class, args) and that throws this exception.
Also, when I build the tar file from command line and then explode the tar file, I do not see my jar file packaged under the lib folder of the tar file. I am clearly missing something, presumably something obvious, but just cannot get the handle to it.
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'application'
id 'idea'
}
mainClassName = 'com.itreatmd.emr.Application'
group = 'com.itreatmd.emr'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jar {
baseName = 'emrServices'
version = '1.0-SNAPSHOT'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jersey'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20180813'
compile "org.apache.httpcomponents:httpmime:4.2.3"
compile group: 'org.yaml', name: 'snakeyaml', version: '1.8'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.1'
compile group: 'org.springframework', name: 'spring-webmvc', version: '3.1.1.RELEASE'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
jar {
manifest {
attributes 'Main-Class': 'com.itreatmd.emr.Application',
'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
}
}
i am using spring boot 2.2.5 and gradle 5.1.2.
run gradle build -x test, it will tell you what error it is.
in my case, it told me that error: package org.jasig.cas.client.authentication does not exist, but this package exists in fact.
then i remembered that i added a dependency runtimeOnly 'org.apereo.cas:cas-server-support-validation:5.3.15.1'
after comment this dependency, my project can start success.

after gradle build success, class not found exception while running spring boot application

I have created spring boot application using Gradle but after successfully building the application when I am trying to run the application it gives me the main class not found an exception.
I am building an application using the below command:
.\gradlew clean build
The build is getting success. But when I try to run the application as a spring boot application then I am getting the error.
Error: Could not find or load main class com.abc.ccs.CommunityApplication
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootjar {
baseName = 'create-community'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'org.postgresql:postgresql'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.2.RELEASE'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
compile group: 'org.codehaus.janino', name: 'janino', version: '3.0.6'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
}
jar {
manifest {
attributes(
"Main-Class": "com.abc.ccs.CommunityApplication"
)
}
}

Springboot project with gradle is failing with error - Multiple bindings

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'
}

Resources