Migration to Spring 6 - spring

I am trying to migrate to Spring 6 and I am getting stuck with following error:
Class org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider does not implement the requested interface jakarta.persistence.spi.PersistenceProvider
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[spring-orm-6.0.2.jar:6.0.2]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.0.2.jar:6.0.2]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.0.2.jar:6.0.2]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.0.2.jar:6.0.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1797) ~[spring-beans-6.0.2.jar:6.0.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1747) ~[spring-beans-6.0.2.jar:6.0.2]
... 58 more
I checked and SpringHibernateJpaPersistenceProvider implements org.hibernate.jpa.HibernatePersistenceProvider which certainly implements jakarta.persistence.spi.PersistenceProvider.
I checked and there does not seem to be other versions on the classpath and also from the stacktrace you can see ~[spring-orm-6.0.2.jar:6.0.2] which means the current version should be correctly used. Where can I search for the error?

This was caused by propagated dependency through c3p0:
implementation("org.hibernate:hibernate-core-jakarta:5.6.14.Final")
implementation("org.hibernate:hibernate-c3p0:5.6.14.Final") {
// propagates unwanted hibernate-core module
exclude(group = "org.hibernate", module = "hibernate-core")
}

Related

spring.jmx.enabled property always set to true

Now, I have a problem about setting a property named spring.jmx.enabled
While upgrading the spring version from 2.2.7 to 2.7.0, we found the following error.
ERROR 2022-09-17 23:27:06 [main] o.s.boot.SpringApplication [tid=] - Application run failed
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (some-service-write)] with key 'writeDataSource'; nested exception is javax.management.InstanceAlreadyExistsException: MXBean already registered with name com.zaxxer.hikari:type=PoolConfig (some-service-write)
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:626)
at org.springframework.jmx.export.MBeanExporter.lambda$registerBeans$2(MBeanExporter.java:552)
at java.util.HashMap.forEach(HashMap.java:1289)
at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:552)
at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:435)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at com.company.team.name.some.SomeServiceApplication.main(SomeServiceApplication.java:16)
Caused by: javax.management.InstanceAlreadyExistsException: MXBean already registered with name com.zaxxer.hikari:type=PoolConfig (some-service-write)
at com.sun.jmx.mbeanserver.MXBeanLookup.addReference(MXBeanLookup.java:151)
at com.sun.jmx.mbeanserver.MXBeanSupport.register(MXBeanSupport.java:160)
at com.sun.jmx.mbeanserver.MBeanSupport.preRegister2(MBeanSupport.java:173)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:930)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:138)
at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:672)
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:616)
... 14 common frames omitted
I searched for this error, and most of them answered that can be solved by setting spring.jmx.enabled to false.
However, I checked that the error continues to occur even if the property corrects this value.
Debugging, this value was coming to true.
I injected properties into the Vm Option like -Dspring.jmx.enabled=false, but I confirmed that the same result came.
How can I set this value to false?
if you define in application.propertiers:
spring.datasource.hikari.registerMbeans=true
you have to disable the default Mbean with this config
#Bean
public MBeanExporter exporter() {
final MBeanExporter exporter = new AnnotationMBeanExporter();
exporter.setAutodetect(true);
exporter.setExcludedBeans("dataSource");
return exporter;
}
for more details : https://github.com/brettwooldridge/HikariCP/issues/342
Make sure you do not have #EnableMBeanExport on your application configuration. It can override the external property.
Learn more about this annotation here: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/EnableMBeanExport.html
You can try changing the default registration policy as below, it will ignore existing bean.
#Configuration
#EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class MXBeansConfig {
}

Spring 5.2.x to 5.3.x upgrade cause ClassNotFoundException for Quartz Jobs under Wildlfy 20

We are using:
JDK 8
Spring 5.2.16.RELEASE
Quartz - 2.3.2
Wildfly 20
Apart from the web application(.war) we have also plugins (.jar) for which the classes are loaded with the following code in the web app:
Thread.currentThread().setContextClassLoader(pluginsClassLoader);
PluginsClassLoader extends URLClassLoader
We are using
org.springframework.scheduling.quartz.QuartzBean to define our own quartz jobs both in the war in the plugins (.jar) e.g. FSSendMessagesWorker extends QuartzBean
in a #Configuration class we have
#Bean
public JobDetailFactoryBean fsPluginSendMessagesWorkerJob() {
JobDetailFactoryBean obj = new JobDetailFactoryBean();
obj.setJobClass(FSSendMessagesWorker.class);
obj.setDurability(true);
return obj;
}
#Bean
#Scope(BeanDefinition.SCOPE_PROTOTYPE)
public SimpleTriggerFactoryBean fsPluginSendMessagesWorkerTrigger()
SimpleTriggerFactoryBean obj = new SimpleTriggerFactoryBean();
obj.setJobDetail(fsPluginSendMessagesWorkerJob().getObject());
obj.setRepeatInterval("* * * 0 1");
obj.setStartDelay(20000);
return obj;
}
After upgrading to Spring 5.3.x it looks like the all classes which extends QuartzBean and present in the .jar files could not be loaded while this was possible (worked) before in Spring 5.2.x
The ones present in the main app (.war) just works fain - are loaded.
Apart from Spring no other library was upgraded.
021-10-05 14:03:25,055 [] [] [] [EE-ManagedExecutorService-quartzExecutorService-Thread-1] ERROR o.s.s.q.LocalDataSourceJobStore:2867 - Error retrieving job, setting trigger state to ERROR.
org.quartz.JobPersistenceException: Couldn't retrieve job because a required class was not found: com.company.plugin.fs.worker.FSSendMessagesWorker from [Module "deployment.mycompany.war" from Service Module Loader]
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1393)
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2864)
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2805)
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2803)
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3864)
at deployment.mycompany.war//org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTriggers(JobStoreSupport.java:2802)
at deployment.mycompany.war//org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:287)
at org.jboss.as.ee#20.0.1.Final//org.jboss.as.ee.concurrent.ControlPointUtils$ControlledRunnable.run(ControlPointUtils.java:105)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:117)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:227)
Caused by: java.lang.ClassNotFoundException: com.company.plugin.fs.worker.FSSendMessagesWorker from [Module "deployment.mycompany.war" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at deployment.domibus-MSH-wildfly-5.0-SNAPSHOT.war//org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at deployment.domibus-MSH-wildfly-5.0-SNAPSHOT.war//org.springframework.scheduling.quartz.ResourceLoaderClassLoadHelper.loadClass(ResourceLoaderClassLoadHelper.java:81)
at deployment.domibus-MSH-wildfly-5.0-SNAPSHOT.war//org.springframework.scheduling.quartz.ResourceLoaderClassLoadHelper.loadClass(ResourceLoaderClassLoadHelper.java:87)
at deployment.domibus-MSH-wildfly-5.0-SNAPSHOT.war//org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectJobDetail(StdJDBCDelegate.java:852)
at deployment.domibus-MSH-wildfly-5.0-SNAPSHOT.war//org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveJob(JobStoreSupport.java:1390)
The quartz has the option to register class loader via the property:
org.quartz.scheduler.classLoadHelper.class
In case setting the TCCL Transaction Context ClassLoader, make sure the cron thread has the same class loader as the class loader, which loads the "classes." In WildFly new threads, get ModuleClassLoader which can have different class scope than the one set back to thread scope in the initial stage.
Try with:
org.quartz.scheduler.classLoadHelper.class = org.quartz.simpl.InitThreadContextClassLoadHelper
Or write a custom ClassHelperLoader class.
https://www.quartz-scheduler.org/api/2.0.2/org/quartz/spi/ClassLoadHelper.html

Spring Integration beans aren't created when spring.main.lazy-initialization=true

With reference to my earlier question here
Spring Boot app fails to start when all beans are marked as Lazy, as it can't find an error channel
and a reference to the issue here:
https://github.com/spring-projects/spring-boot/issues/16184#issuecomment-480196051
does anyone know what beans need to be added to an instance of LazyInitializationExcludeFilter in order for Spring Integration to start when spring.main.lazy-initialization=true ?
I'm getting errors like below, saying that "myErrorChannel" bean isn't available, where this is defined in code like so:
#MessagingGateway(errorChannel = "myErrorChannel")
#FunctionalInterface
public interface SomeInterface{
}
How can I make the creation of the error channel eager rather than lazy ? Adding a LazyInitializationExcludeFilter and trying to filter out beans called "myErrorChannel" doesn't work, as there must be another (lazy) bean that isn't creating the errorChannel bean.
Stacktrace:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myErrorChannel' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:805)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1278)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:89)
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:46)
at org.springframework.integration.gateway.MessagingGatewaySupport.getErrorChannel(MessagingGatewaySupport.java:414)
at org.springframework.integration.graph.IntegrationGraphServer$NodeFactory.gatewayNode(IntegrationGraphServer.java:374)
at org.springframework.integration.graph.IntegrationGraphServer.lambda$gateways$5(IntegrationGraphServer.java:258)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet.lambda$entryConsumer$0(Collections.java:1577)
at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1699)
at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntrySetSpliterator.forEachRemaining(Collections.java:1602)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
at org.springframework.integration.graph.IntegrationGraphServer.gateways(IntegrationGraphServer.java:263)
at org.springframework.integration.graph.IntegrationGraphServer.buildGraph(IntegrationGraphServer.java:184)
at org.springframework.integration.graph.IntegrationGraphServer.onApplicationEvent(IntegrationGraphServer.java:115)
at org.springframework.integration.graph.IntegrationGraphServer.onApplicationEvent(IntegrationGraphServer.java:66)
Solved by making any beans that are created in this manner as lazy:
#Bean
public IntegrationFlow someBeanName() {
return IntegrationFlows.from("someString")
.handle(restCallFailedHandler())
.handle(finishedHandler())
.get();
}

Kotlin and spring boot data resource exception

I'm trying out kotlin and spring boot with spring data.
id("org.springframework.boot") version "2.1.8.RELEASE"
I have some schema-*.sql files in src/main/resources. I put this in my application.properties
spring.datasource.schema=/sql/schema-*.sql
I then made a small spring boot ApplicationRunner-based app (so set WebApplicationType.NONE) and these all get executed as expected and the app starts fine.
#SpringBootApplication
private class MainApp(): ApplicationRunner { ... }
fun main(args: Array<String>) {
runApplication<MainApp>(*args) {
webApplicationType = WebApplicationType.NONE
}
}
Now, when I change the above to WebApplicationType.SERVLET, I get the following:
Caused by: java.io.FileNotFoundException: ServletContext resource [/sql/] cannot be resolved to URL because it does not exist
at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:173) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:498) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:298) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.getResources(ClassLoaderFilesResourcePatternResolver.java:109) ~[spring-boot-devtools-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.context.support.GenericApplicationContext.getResources(GenericApplicationContext.java:233) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:76) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:42) ~[spring-jdbc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.doGetResources(DataSourceInitializer.java:175) ~[spring-boot-autoconfigure-2.1.8.RELEASE.jar:2.1.8.RELEASE]
... 89 common frames omitted
This exception goes away and the http server seems to be fine when I omment out:
spring.datasource.schema=/sql/schema-*.sql
Any ideas what I'm supposed to change to make this work?
Try that spring.datasource.schema=classpath:sql/schema-*.sql.

problems with getting basic logging up with springboot and logback

i have a simple spring boot app in groovy. here are the gradle dependencies i have set so far
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.easyrules:easyrules-core:2.2.1-SNAPSHOT'
compile 'org.easyrules:easyrules-spring:2.2.1-SNAPSHOT'
compile 'org.easyrules:easyrules-jmx:2.2.1-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'ch.qos.logback:logback-classic:1.1.5'
}
this brings in slf4j-api, log4j-over-slf4j, jul-to-slf4j, and jcl-over-slf4f at versions 1.7.13
then in my helper class i have this
#Component
#PropertySource ("classpath:application.properties")
class RulesHelper {
private static final Logger log = LoggerFactory.getLogger(RulesHelper.class)
followed by a bean def like this
#Bean
def rulesEngine () {
assert jmxEnabled != null
if ( !jmxEnabled ) {
//return std rules engine
println "returning std rules engine of type ${stdRulesEngine.getClass().name}"
ruleEngine = stdRulesEngine
return stdRulesEngine
} else {
println "returning jmx rules engine of type ${jmxRulesEngine.getClass().name}"
//log.debug("hello from logger")
//assert log
ruleEngine = jmxRulesEngine
return jmxRulesEngine //JmxRulesExtends RulesEngine so should work
}
}
if i uncomment out that assert i get an error when i run like this saying it cant find org.slf4j.event.LoggingEvent
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Object]: Factory method 'rulesEngine' threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:85)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:82)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:251)
at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:361)
at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:340)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3224)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:222)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:253)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:263)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:259)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:855)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:888)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:880)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean(DefaultTypeTransformation.java:180)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.booleanUnbox(DefaultTypeTransformation.java:69)
at org.softwood.easyrules.RulesHelper.rulesEngine(RulesHelper.groovy:79)
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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.slf4j.event.LoggingEvent
what have i done wrong here - i thought this would work based on what i have read
well what do you know - dependency management issue - the latest springboot-starter-logging is only using slf4j-api.1.7.13,
however if you get the latest logback which i did logback_classic.1.1.5 there was breaking issue somewhere in the Api client librray that didnt export the class - which is why it couldnt be found. see logback issue/news
if you explicitly add the dependency
...
compile 'ch.qos.logback:logback-classic:1.1.5'
compile 'org.slf4j:slf4j-api:1.7.16'
to gradle.build, refresh and retry it all starts to work as nature expected. Blimey painful as usual as these things normally are
java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
Logback-classic version 1.1.4 and later require slf4j-api version 1.7.15 or later.
With an earlier slf4j-api.jar in the classpath, attempting introspection of a Logger instance returned by logback version 1.1.4 or later will result in a NoClassDefFoundError similar to that shown below.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.privateGetPublicMethods(Class.java:2571)
at java.lang.Class.getMethods(Class.java:1429)
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1261)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1122)
at java.beans.Introspector.getBeanInfo(Introspector.java:414)
at java.beans.Introspector.getBeanInfo(Introspector.java:161)
Placing slf4j-api.jar version 1.7.15 or later in the classpath should solve the issue.
Note that this problem only occurs with logback version 1.1.4 and later, other bindings such as slf4j-log4j, slf4j-jdk14 and slf4j-simple are unaffected.
corresponding maven dependency missing got it from https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.15
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.15</version>
</dependency>

Resources