PDA

View Full Version : Spring MVC - class def not found exception


lkamal
Mar 27th, 2007, 03:49 AM
Hi all,

I have faced an issue with class loading in Spring MVC.

1. com.myCompany.refproj.service.suite.SuiteServicePo ol - a class in refproj project, there's nothing related to this class in the config file. This class is available inside a jar file. In the config file, <bean> tag not used with this class.

2. com.myCompany.dataManager.customer.CustomerService - a class in dataManager project. In the config file, <bean> tag is used with this class.

CustomerService class looks like follows.

package com.myCompany.dataManager.customer;

import com.myCompany.refproj.service.suite.SuiteServicePo ol;

public class CustomerService{
public CustomerService() {
SuiteServicePool cs = new SuiteServicePool();
}
}
The imports statement in this class works fine.

3. dataManager-servlet.xml - config file

<bean id="customerService"
class="com.myProject.dataManager.customer.CustomerService">
</bean>

But when the CustomerService class is instantiated through config file, the following exception is thrown.

Could you please help me on this? SuiteServicePool class is inside a jar file and I have added that jar file into the lib folder and project doesn't have any errors when opened with Eclipse. Is there a requirement to add the paths to jar files into the config file other than adding them to the project?

Thanks in advance.

BR,
Kamal Mettananda (http://lkamal.blogspot.com)

------------------------------------------------------------
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'customerService' defined in ServletContext resource [/WEB-INF/dataManager-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.myCompany.dataManager.customer.CustomerService]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/myCompany/refProj/service/suite/SuiteServicePool
org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.myCompany.dataManager.customer.CustomerService]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/myCompany/refProj/service/suite/SuiteServicePool
java.lang.NoClassDefFoundError: com/myCompany/refProj/service/suite/SuiteServicePool
at com.myCompany.dataManager.customer.CustomerService .<init>(CustomerService.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:494)
at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:171)
at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:148)
at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:52)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:486)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:362)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:283)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:313)
at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:139)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:3 06)
at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:251 )
at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:220)
at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:112)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:3951)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4225)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:904)
at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:432)
Mar 27, 2007 12:19:38 PM org.apache.catalina.core.ApplicationContext log

Marten Deinum
Mar 27th, 2007, 04:32 AM
Make sure that the library is also in the distribution and gets copied to the correct file.

lkamal
Mar 27th, 2007, 05:01 AM
I have my jar files under WEB-INF/lib and WEB-INF/lib/suiteJars.

In the war file I can see all of the jar files. I think the issue is that Spring can not load the jar fies in WEB-INF/lib/suiteJars folder.

BR,
Kamal Mettananda (http://lkamal.blogspot.com)

Marten Deinum
Mar 27th, 2007, 06:00 AM
That has nothing to do with Spring. Only jar files in the WEB-INF/lib directory will be loaded by the webcontainer. Anything in subdirectories will be ignored.