Spring Boot and Vaadin - ClassNotFoundException: org.springframework.web.context.support.WebApplicationObjectSupport - spring-boot

I have generated Spring Boot Vaadin project at start.spring.io with just the Vaadin dependency (Maven project, Spring Boot 1.5.1, Vaadin dependency).
I have unzipped the dowloaded .zip file and imported the project to STS (File -> Import -> Existing Maven Projects). I tried to run the application but I got this exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/web/context/support/WebApplicationObjectSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
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)
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.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:640)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:425)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:515)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:508)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1189)
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:862)
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:848)
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:834)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:788)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at com.example.MyvaadinApplication.main(MyvaadinApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.support.WebApplicationObjectSupport
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)
... 60 more
The project can be build by Maven (clean install) when skipping tests. With tests enabled it fails with the same error.
I have already tried:
to import project and run it in different IDEs (STS, Eclipse, Idea)
run the application as Spring Boot App, Java Application, from test class
other versions of Spring Boot (1.5.1, 1.4.4)
different Java 8 (jdk1.8.0_65, jdk1.8.0_121)
restart IDE

Based on the comment from p.streef I found the solution. I cleared Maven repository (more precisely I deleted content of .m2\repository\org\springframework folder where Spring .jar files are located) and run the application again. Then it worked.
Edit
It seems like frequent problem. Recently I tried to create a new Spring Boot project with Vaadin, JPA and H2 dependencies. At first I got:
spring boot Error creating bean with name 'entityManagerFactory'
I deleted jars in .m2\repository\org\hibernate and run mvn clean install and got:
spring boot NoClassDefFoundError: javassist/bytecode/ClassFile
I deleted jars in .m2\repository\org\javassist and run mvn clean install
Now it worked. So when you get some error running newly created Spring Boot project saying that some class is missing, clean jars in your Maven repository and try it again.

Related

ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener when running JUnit5

In my Intelly Idea's Gradle-based project (Java Spring Boot ver. '2.0.3.RELEASE') when i try to debug an unit-test i'm getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:45)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
Gradle edition is 4.8
Gradle dependecies are:
testCompile("junit:junit:4.12")
testCompile(
'org.junit.jupiter:junit-jupiter-api:5.1.0'
)
testRuntime(
'org.junit.jupiter:junit-jupiter-engine:5.1.0',
'org.junit.vintage:junit-vintage-engine:5.1.0',
'org.junit.platform:junit-platform-launcher:1.1.0',
'org.junit.platform:junit-platform-runner:1.1.0'
)
What setting(s) am I missing and how can I resolve this problem?
Try running
gradle test
on the command line. This should show more verbose output to help diagnose the problem.

ClassNotFoundException for Ebean only in IntelliJ

I keep getting following exceptions when I run a Spring Application from IntelliJ
Caused by: java.lang.NoClassDefFoundError:
com/avaje/ebean/bean/EntityBean at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(ClassLoader.java:763) at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at
java.net.URLClassLoader.access$100(URLClassLoader.java:73) at
java.net.URLClassLoader$1.run(URLClassLoader.java:368) at
java.net.URLClassLoader$1.run(URLClassLoader.java:362) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:361) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) 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.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
... 32 common frames omitted Caused by:
java.lang.ClassNotFoundException: com.avaje.ebean.bean.EntityBean at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 51 common
frames omitted
however, if I try to run the jar from command line, it works fine. I turned on the Enhance Beans plugin. not even sure what could be the problem.
turns out my Ebean enhancement plugin is in mismatched version, upgraded to latest version and it is all working again.

Spring Cloud Config Client - Angel.SR4 vs Boot 1.3.1?

All,
I've built Spring Cloud Config servers and clients before with previous versions of Spring Cloud / Spring Boot, but I seem to be having an issue with the Angel.SR4 / Boot 1.3.1 combination.
Following the basic instructions here (http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_client_side_usage), except using the current releases of Boot and Cloud (1.3.1.RELEASE / Angel.SR4 at present), I get the following stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.logging.ClasspathLoggingApplicationListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:392)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:383)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:263)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113)
at demo.Application.main(Application.java:10)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:405)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 21 more
If I back off the Boot version to 1.2.8 the problem disappears. If I move Cloud up to Brixton.M4 the problem disappears. Is there a prescribed version combination of Boot / Cloud that should be used together? Thanks in advance.
K
Is there a prescribed version combination of Boot / Cloud that should be used together?
Yes. Angel is Boot 1.2, and Brixton is Boot 1.3. See the blog for more detail: https://spring.io/blog/2015/11/25/migrating-spring-cloud-apps-from-spring-boot-1-2-to-1-3

Trouble setting Classpath for Cpsuite with Maven

Using Maven I am creating a jar-with-dependencies for a project that uses ClasspathSuite to create a JUnit test suite. When running the jar from the command line I am running into an issue where the project classpath isn't being supplied like it would be in Eclipse.
Exception in thread "main" java.lang.NoClassDefFoundError: com/<dir>/BaseCategoryRunner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: com.<dir>.BaseCat
egoryRunner
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
I need the project classpath so that ClasspathSuite can scan my files to build a junit class suite. I have been searching a number of ways to allow maven to include the classpath in my pom such as <additionalClasspathElements> or <Class-Path> but I cannot get the value to appear in the system property java.class.path. At this point I am unsure if I am just walking down a rabbit hole that isn't going to work.
Is it possible to have a classpath in my jar's manifest that will point to one of the jar's directory? In this case ./com/....
How can I have this classpath referenced so that maven will include it when the jar is executed?

Error in Eclipse Luna: java.lang.NoClassDefFoundError: org/eclipse/osgi/baseadaptor/HookConfigurator

I write project work with osgi + aspectj. It work ok in Eclipse Kepler, but when I upgrade to eclipse 4.4 (Luna) then get error:
I open org.eclipse.osgi*.jar found in Eclipse Kepler and see class org.eclipse.osgi.baseadaptor.HookConfigurator
But in Luna not found.
!SESSION 2014-07-16 09:40:14.127 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_45
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
!ENTRY org.eclipse.osgi 4 0 2014-07-16 09:40:14.480
!MESSAGE error loading hook: org.eclipse.equinox.weaving.hooks.WeavingHook
!STACK 0
Full Stacktrace
java.lang.NoClassDefFoundError: org/eclipse/osgi/baseadaptor/HookConfigurator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.eclipse.osgi.internal.hookregistry.HookRegistry.loadConfigurators(HookRegistry.java:185)
at org.eclipse.osgi.internal.hookregistry.HookRegistry.initialize(HookRegistry.java:106)
at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:73)
at org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:31)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:297)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.lang.ClassNotFoundException: org.eclipse.osgi.baseadaptor.HookConfigurator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 38 more
[org.eclipse.equinox.weaving.aspectj] info Starting AspectJ weaving service ...
-----------------------
Before execution sum
Value =200
-----------------------
Value =200
-----------------------
Value =200.0
[org.eclipse.equinox.weaving.caching.j9] warning cannot start J9 caching service
[org.eclipse.equinox.weaving.caching] info starting standard caching service ...
osgi>
I have followed the instructions here, it's based on Eclipse Kepler, but I use Eclipse Luna.
Please help me.
Equinox Luna has change many of the internal details that require all equinox framework hook implementations to be migrated to use the new hooks. It is unclear to me what you have installed that is trying to implement HookConfigurator from the stacktrace. If it is the Equinox weaving support which supports weaving with aspectj then you will need the Equinox weaving bundles released with the Equinox 4.4 (luna) release as well.
If not then what ever framework extension you have installed that does weaving will need to be migrated to the new Equinox framework specific hooks in luna.

Resources