Announcement Announcement Module
Collapse
No announcement yet.
How to troubleshoot ClassNotFoundException ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to troubleshoot ClassNotFoundException ?

    Hello,

    I'm using Jetty 8.1.3.v20120416 (embedded) as my container. Spring version 3.0.5-RELEASE. My dependencies are managed by maven.

    Today I tried to create Jetty's HTTP client as a bean in WEB-INF/applicationContext.xml:
    <bean id="my-http-client" class="org.eclipse.jetty.client.HttpClient" />

    and during app startup (eg, loading WEB-INF/applicationContext.xml), it failed with "java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient". I'll put the stack trace at the bottom.

    This is baffling because I am positive HttpClient is on the classpath because I have another utility class that creates 2 instances of it. That code has been in use for at least a year.

    I'm running this from Eclipse so I can examine the process classpath and I see the correct jars there and no duplicate jars. Like I said the classpath is managed by maven (m2eclipse in this case) so it mostly takes care of jar conflicts.

    I have 2 questions:
    1. Any ideas why Spring (using ContextLoaderListener) cannot find this class while my factory class has no problem?
    2. Assuming this is some sort of weird classloader issue, any suggestions on how I could debug that?

    Any advice greatly appreciated.
    -- Colin


    Partial stack trace:
    Caused by: org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'directTenforeServiceImpl' defined in file [/home/colini/workspace_indigo/cdb-all/target/classes/com/lim/cd/service/tenfore/direct/DirectTenforeServiceImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.lim.cd.service.tenfore.PollerService]: : Cannot find class [org.eclipse.jetty.client.HttpClient] for bean with name 'my-http-client' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient; nested exception is org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.eclipse.jetty.client.HttpClient] for bean with name 'my-http-client' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient
    at org.springframework.beans.factory.support.Construc torResolver.createArgumentArray(ConstructorResolve r.java:730) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:196) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:1003) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:907) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:485) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 ) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895) ~[spring-context-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425) ~[spring-context-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at com.lim.cd.config.SpringBootstrapper.afterProperti esSet(SpringBootstrapper.java:48) ~[classes/:na]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    ... 30 common frames omitted
    Caused by: org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.eclipse.jetty.client.HttpClient] for bean with name 'my-http-client' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1250) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.predictBeanType(Abstrac tAutowireCapableBeanFactory.java:576) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :1319) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanNamesForType(DefaultList ableBeanFactory.java:315) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.BeanFactoryUtils .beanNamesForTypeIncludingAncestors(BeanFactoryUti ls.java:185) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.findAutowireCandidates(DefaultL istableBeanFactory.java:829) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:786) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:703) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Construc torResolver.resolveAutowiredArgument(ConstructorRe solver.java:795) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Construc torResolver.createArgumentArray(ConstructorResolve r.java:723) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    ... 45 common frames omitted
    Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.client.HttpClient
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366) ~[na:1.7.0_15]
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355) ~[na:1.7.0_15]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_15]
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354) ~[na:1.7.0_15]
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadCla ss(WebAppClassLoader.java:415) ~[jetty-webapp-8.1.3.v20120416.jar:8.1.3.v20120416]
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadCla ss(WebAppClassLoader.java:377) ~[jetty-webapp-8.1.3.v20120416.jar:8.1.3.v20120416]
    at org.springframework.util.ClassUtils.forName(ClassU tils.java:257) ~[spring-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java:408) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.doResolveBeanClass(AbstractBeanFactory .java:1271) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1242) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    ... 54 common frames omitted

  • #2
    I'm happy to answer my own question. It turns out Jetty has a default list of classes and packages that it will not allow web apps to create (aka "server" classes.) Jetty whitelists a few org.eclipse.jetty packages then blocks everything in org.eclipse.jetty.*, which includes the HttpClient I was trying to instantiate. Once I added it to the whitelist the problem went away.

    Thanks, colini!

    Comment

    Working...
    X