springboot 1.5.2 + hibernate-search-orm - java

I want to use springboot and hibernate-search-orm but can't get the project to compile.
I think it is because of compatability issues between hibernate versions?
I am using Gradle and Intellij Idea.
build.gradle
buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
ext["thymeleaf.version"] = "3.0.2.RELEASE"
ext["thymeleaf-layout-dialect.version"] = "2.0.1"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.5-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile 'org.springframework.boot:spring-boot-starter-security'
compile ("org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.0.RELEASE")
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '1.5.2.RELEASE'
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '2.1.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.2.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-search-orm',
version: '5.1.0.Final'
compile("org.springframework.boot:spring-boot-devtools")
compile('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
bootRun {
addResources = true
}
And the output when I run build
5:40:30 PM: Executing external task 'build'...
C:\Users\Owner\IdeaProjects\test\src\main\java\com\example\controllers\planController.java:27: warning: sym is internal proprietary API and may be removed in a future release
import static com.sun.org.apache.xalan.internal.xsltc.compiler.sym.error;
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
:compileJava
:processResources UP-TO-DATE
:classes
:findMainClass
:jar
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
com.example.Demo3ApplicationTests > contextLoads FAILED
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: java.lang.AbstractMethodError
1 test completed, 1 failed
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Users/Owner/IdeaProjects/test/build/reports/tests/test/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 23.392 secs
There were failing tests. See the report at: file:///C:/Users/Owner/IdeaProjects/test/build/reports/tests/test/index.html
5:40:54 PM: External task execution finished 'build'.
I don't think hibernate-search-orm is part of springboot so I have added it to my build.gradle file explicitly.
If I try to run my project the root error appears to be:
Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)

You need to Specify the versions of dependencies that you are using. And they should be compatible to each other.Go through https://mvnrepository.com and find your spring boot version and check Compile Dependencies. Do it with all other dependencies that you are using .

Related

Trying to upgrade Groovy app from 2.3.1 to 3.3.15, I am getting lots of errors like below. any help will be appriciated

| Running application...
2022-10-11 17:19:04.189 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [splitseasontickets.main4.Application]; nested exception is java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:561)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:187)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:300)
at grails.boot.GrailsApp.run(GrailsApp.groovy:55)
at grails.boot.GrailsApp.run(GrailsApp.groovy:374)
at grails.boot.GrailsApp.run(GrailsApp.groovy:363)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at splitseasontickets.main4.Application.main(Application.groovy:8)
Caused by: java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.handleInvalidExcludes(AutoConfigurationImportSelector.java:183)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.checkExcludedClasses(AutoConfigurationImportSelector.java:169)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:97)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:552)
... 19 common frames omitted
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full trace)
I am using the below dependencies in gradle...
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
}
}
version "0.1"
group "splitseasontickets.main4"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
mavenCentral()
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.16.Final"
compile "org.grails.plugins:gsp"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime 'org.glassfish.web:el-impl:2.2'
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime 'com.bertramlabs.plugins:asset-pipeline-grails:3.4.7'
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb:1.1.2"
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0'
testRuntime 'net.sourceforge.htmlunit:htmlunit:2.64.0'
testRuntime 'org.seleniumhq.selenium:selenium-chrome-driver:4.5.0'
// compile "org.grails.plugins:hibernate"
compile "org.hibernate:hibernate-ehcache"
testCompile "org.grails:grails-plugin-testing"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.1-beta2'
compile 'org.grails:grails-datastore-rest-client:6.1.9.RELEASE'
compile 'org.codehaus.groovy:groovy-sql:3.0.13'
//compile group: 'org.grails', name: 'grails-web-common', version: '3.0.17'
compile group: 'org.grails', name: 'grails-core', version: '3.1.14'
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'org.jmdware', name: 's3-bucket-recursor', version: '1.0.1'
// compile group: 'org.apache.camel', name: 'camel-grape', version: '3.19.0'
//compile 'org.grails.plugins:spring-security-core:3.0.3'
compile 'org.grails.plugins:spring-security-core:3.2.0.M1'
compile 'org.grails.plugins:spring-security-ui:3.1.2'
compile 'org.springframework.boot:spring-boot-starter-security:1.5.4.RELEASE'
compile group: 'org.grails', name: 'grails-plugin-controllers', version: '3.3.16'
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}
assets {
minifyJs = true
minifyCss = true
}
maven { url "https://maven.repository.redhat.com/ga/"}
compile 'org.springframework:org.springframework.beans:2.5.6.SEC01'
Try with this

Spring boot Data JPA task :test Failed

I'm starting to use Data JPA from Spring to interact with Postgres Database, but when I try to build the project, the building phase raise an exception in the applicationTest.
This is my build.gradle:
plugins {
id 'org.springframework.boot' version '2.5.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'eu.universome.radio'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
If I comment the dependencies:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' the build will be successful.
This is my empty applicationTest:
package eu.universome.radio.RadioUVMServer;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
#SpringBootTest
class RadioUvmServerApplicationTests {
#Test
void contextLoads() {
}
}
Here there is the Console Error:
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 7.1.1
Java Home: /usr/lib/jvm/java-11-openjdk-amd64
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: build
> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :bootJarMainClassName
> Task :bootJar
> Task :jar UP-TO-DATE
> Task :assemble
> Task :compileTestJava
> Task :processTestResources UP-TO-DATE
> Task :testClasses
> Task :test FAILED
RadioUvmServerApplicationTests > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:658
Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:185
Caused by: java.lang.IllegalStateException at Assert.java:97
1 test completed, 1 failed
Here you can find the report:
[1]: https://www.universome.eu/wp-content/uploads/RadioUVM/progetto-radio-unime/reports/tests/test/classes/eu.universome.radio.RadioUVMServer.RadioUvmServerApplicationTests.html
Not sure if you have the dependency added.
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.23'
You can check if the driver is on classpath:
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
// recheck dependencies
}
Solved adding the line
runtimeOnly 'org.postgresql:postgresql'
on build.gradle file in section dependencies
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

IntelliJ Idea doesn't see dependency, which was added by Gradle

I have such build.gradle file:
group 'com.test'
version '1.0'
apply plugin: 'java'
sourceCompatibility = 1.5
jar {
baseName = 'test'
version = '0.0.1'
}
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
ext{
//versions of dependencies
springVersion = '5.0.4.RELEASE'
springBootVersion = '2.0.0.RELEASE'
springJPAVersion = '2.0.5.RELEASE'
javaxVersion = '1.0.2'
}
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}"
testImplementation group: 'junit', name: 'junit', version: '4.11'
}
And build task is executed successfully:
21:56:37: Executing external task 'build'...
:compileJava UP-TO-DATE
:processResources NO-SOURCE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test NO-SOURCE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 up-to-date
21:56:37: External task execution finished 'build'.
And in C:\Users\admin.gradle\caches\modules-2\files-2.1\javax.persistence\persistence-api\1.0.2\8...a Gradle downloaded archive persistence-api-1.0.2.jar, which contains javax\persistence\Entity.class.
But when I'm trying to add line:
import javax.persistence.Entity;
in any class, IntelliJ Idea underlines persistence with red. Why, and how to fix it?
At last I've pushed "Refresh all Gradle project" in Gradle projects window:
and all dependencies suddenly appeared in module's dependencies in Project Structure. And after that my problem was fixed.

IntelliJ can't find slf4j logger with gradle

I have a project for which I use gradle, and I wanted to use the logger slf4j provides.
Running in Android Studio produces the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.mypkg.Main.<clinit>(Main.java:9)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
My build.gradle for the project:
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.0'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'application'
jar {
manifest {
attributes 'Main-Class': "Main"
}
}
shadowJar {
mergeServiceFiles('META-INF/spring.*')
}
mainClassName = 'com.mypkg.Main'
dependencies {
compile 'com.squareup:otto:1.3.5'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
compile 'com.squareup.okhttp:okhttp:2.7.4'
compile 'com.squareup.okhttp:okhttp-ws:2.7.4'
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'org.json:json:20140107'
compile 'org.bouncycastle:bcprov-jdk15on:1.52'
compile 'commons-codec:commons-codec:1.10'
compile 'org.scream3r:jssc:2.8.0'
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'ch.qos.logback:logback-core:1.1.3'
compile 'org.json:json:20140107'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'org.springframework.shell', name: 'spring-shell', version: '1.2.0.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version: '4.2.4.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '4.2.4.RELEASE'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
If I build this project with gradle, the shadow plugin generates a fat jar, which runs from the console nicely, it includes the logger, but from the IDE I'm having difficulties finding the LoggerFactory. I read here that I should add the logger to the classpath but since I don't explicitly include a jar, rather than marking it as a dependency, I'm not sure how this would be possible.
Please advise.
Cheers!
The classpath is out of sync, few options here
Refresh the project in IntelliJ (the older versions of IntelliJ are not ideal with gradle integration)
add apply plugin: 'idea' to your build.gradle and then run gradle idea to regenerate .iml .ipr .iws files in your project and pick up dependencies from gradle.(Not ideal! see why)
Download latest version of IntelliJ and redo option 1
Edit: Thanks #CrazyCoder for this hint.

how to properly configure gradle build to avoid including log4j and slf4j from the resulting jar?

I'm having an issue with my spring-boot application: I'm able to run it within Eclipse, but unable to run the jar file (built with gradle).
I run the following command to build my project:
gradle buid
The build is successful:
gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:jar
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.214 secs
This is a fragment of the resulting jar file:
jar -tvf build/libs/springboot-receiver-api-0.1.0.jar | grep log
9988 Mon Apr 04 20:37:48 CDT 2016 BOOT-INF/lib/slf4j-log4j12-1.7.21.jar
2308 Wed Sep 21 07:11:50 CDT 2016 BOOT-INF/lib/spring-boot-starter-logging-1.4.1.RELEASE.jar
66802 Thu May 28 09:49:34 CDT 2015 BOOT-INF/lib/jboss-logging-3.3.0.Final.jar
304075 Tue Mar 29 22:24:50 CDT 2016 BOOT-INF/lib/logback-classic-1.1.7.jar
23646 Mon Apr 04 20:39:02 CDT 2016 BOOT-INF/lib/log4j-over-slf4j-1.7.21.jar
470782 Tue Mar 29 22:23:42 CDT 2016 BOOT-INF/lib/logback-core-1.1.7.jar
489884 Sun May 06 13:24:48 CDT 2012 BOOT-INF/lib/log4j-1.2.17.jar
when I attempt to run this jar file, I get this error:
java -jar build/libs/springboot-receiver-api-0.1.0.jar
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/eugene/.Trash/springboot-receiverapi/build/libs/springboot-receiver-api-0.1.0.jar!/BOOT-INF/lib/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/eugene/.Trash/springboot-receiverapi/build/libs/springboot-receiver-api-0.1.0.jar!/BOOT-INF/lib/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
Caused by: java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
at org.slf4j.impl.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:54)
... 19 more
Here is my build.gradle file:
apply plugin: 'java'
apply plugin: 'maven'
group = 'uptake'
version = '0.0.1-snapshot'
description = """Spring-Boot-ReceiverAPI"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.2.3.RELEASE') {
exclude(module: 'log4j-over-slf4j')
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.2.3.RELEASE'
compile group: 'org.postgresql', name: 'postgresql', version:'9.3-1102-jdbc41'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate4', version:'2.8.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.8.3'
compile group: 'org.apache.kafka', name: 'kafka_2.10', version:'0.9.0.0'
compile group: 'org.springframework.integration', name: 'spring-integration-kafka', version:'2.0.1.RELEASE'
compile group: 'org.apache.zookeeper', name: 'zookeeper', version:'3.4.5'
compile(group: 'commons-beanutils', name: 'commons-beanutils', version:'1.9.2') {
exclude(module: 'commons-logging')
}
compile group: 'org.json', name: 'json', version:'20090211'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version:'1.5.0'
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.3.RELEASE') {
exclude(module: 'commons-logging')
}
compile group: 'com.spotify', name: 'docker-maven-plugin', version:'0.4.13'
}
configurations.all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
What can I do, to avoid this clash of logging libraries, and to be able to run my jar file stand-alone?
Couple things, it seems to me that your build.gradle should declare :
spring boot gradle plugin
apply spring boot plugin
let spring boot manage most of your dependency versions
This script works for me:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
group = 'uptake'
version = '0.0.1-snapshot'
description = """Spring-Boot-ReceiverAPI"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE'
}
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.postgresql:postgresql'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate4'
compile 'com.fasterxml.jackson.core:jackson-core'
compile 'org.apache.kafka:kafka_2.10:0.9.0.0'
compile 'org.springframework.integration:spring-integration-kafka:2.0.1.RELEASE'
compile 'org.apache.zookeeper:zookeeper:3.4.5'
compile 'commons-beanutils:commons-beanutils'
compile 'org.json:json'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.5.0'
compile 'org.springframework:spring-core'
compile 'com.spotify:docker-maven-plugin:0.4.13'
}
configurations.all {
exclude module: 'slf4j-log4j12'
exclude module: 'jms'
exclude module: 'jmxtools'
exclude module: 'jmxri'
}
Now, if you check both modules with gradle dependencyInsight, only log4j-over-slf4j will be found:
$ gradle dependencyInsight --dependency slf4j-log4j12
$ No dependencies matching given input were found...
$ gradle dependencyInsight --dependency log4j-over-slf4j
:dependencyInsight
org.slf4j:log4j-over-slf4j:1.7.21 (selected by rule)
\--- org.springframework.boot:spring-boot-starter-logging:1.4.1.RELEASE
+--- compile
\--- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE
+--- compile
+--- org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE
| \--- compile
+--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.1.RELEASE
| \--- compile
+--- org.springframework.boot:spring-boot-starter-aop:1.4.1.RELEASE
| \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.1.RELEASE (*)
\--- org.springframework.boot:spring-boot-starter-jdbc:1.4.1.RELEASE
\--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.1.RELEASE (*)
I solved this problem updating kafka to a new version.
Some old versions of Kafka had dependecies with jmxtools and jmxri (from log4j < 1.2.16). And this dependecies doesn't have available licences in maven and gradle.
You can resolve this doing one of this three options:
Setting kafka in a major version(2.12 works well!)
Setting log4j in a version upper to 1.2.16
Excluding jmxtools and jmxri
Like I previously said, I resolved this setting the kafka version in my build.gradle:
compile group: 'org.apache.kafka', name: 'kafka_2.12', version: '2.4.0'

Categories

Resources