ScrappyDev
ScrappyDev

Reputation: 2778

Why/How am I getting the error: NoClassDefFoundError: org/springframework/aop/framework/ProxyFactory

Goal: Start up a server which supports remote access to method calls.

The application doesn't fail till after all services are created.

The jar is in the target/lib directory.

Parent pom has the dependency:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${version.spring}</version>
</dependency>

Note: I am able to create a spring bean of type: org.springframework.aop.framework.ProxyFactory

Stack Trace:

36438 [main] ERROR org.springframework.web.context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.rmi.RmiServiceExporter#0' defined in class path resource [application-context-service-web-server.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/framework/ProxyFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3795)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/ProxyFactory
    at org.springframework.remoting.support.RemoteExporter.getProxyForService(RemoteExporter.java:156)
    at org.springframework.remoting.rmi.RmiBasedExporter.getObjectToExport(RmiBasedExporter.java:61)
    at org.springframework.remoting.rmi.RmiServiceExporter.prepare(RmiServiceExporter.java:268)
    at org.springframework.remoting.rmi.RmiServiceExporter.afterPropertiesSet(RmiServiceExporter.java:227)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
    ... 39 more

application-context-service-web-server.xml:

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
    <!-- does not necessarily have to be the same name as the bean to be exported -->
    <property name="serviceName" value="Manager1" />
    <property name="service" ref="manager1" />
    <property name="serviceInterface" value="com.service.Manager1" />
    <!-- defaults to 1099 -->
    <property name="registryPort" value="1199" />
</bean>

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
    <!-- does not necessarily have to be the same name as the bean to be exported -->
    <property name="serviceName" value="Manager2" />
    <property name="service" ref="manager2" />
    <property name="serviceInterface" value="com.service.Manager2" />
    <!-- defaults to 1099 -->
    <property name="registryPort" value="1199" />
</bean>

<bean id="manager1"
      class="com.service.impl.Manager1Impl">
    ...
</bean>

<bean id="manager2"
      class="com.service.impl.Manager2Impl">
    ...
</bean>

NOTE: This works, but the above still fails

<bean id="proxied" class="org.springframework.aop.framework.ProxyFactory" />
Thread [main] (Suspended (entry into method  in ProxyFactory))   
    ProxyFactory.() line: 40  
    NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]   
    NativeConstructorAccessorImpl.newInstance(Object[]) line: 39    
    DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27    
    Constructor.newInstance(Object...) line: 494 

Upvotes: 4

Views: 16573

Answers (3)

Rajkumar Teckraft
Rajkumar Teckraft

Reputation: 69

please add the spring-aop-X.X.X.jar to your project libraries which related to spring version jars you are using. Then the problem will be resolved.
If you don't use the appropriate version of the jars, you keep on getting this errors.

The functionality may not work if you add different version of jars in spring. Kindly make sure the same version for best developers practices.

Thanks!.

Upvotes: 0

ScrappyDev
ScrappyDev

Reputation: 2778

This turned out to be an eclipse environment issue.
I use the SysDeo Tomcat Plugin.
Under Window > Preferences > Tomcat > Source Path I had to uncheck all the projects except the client and server projects.

Upvotes: 0

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340708

Please double-check that you have the following dependencies as well:

  • aopalliance.jar
  • spring-core.jar

NoClassDefFoundError does not say that it can't find ProxyFactory class - indeed, it has been found, but some of its dependencies are missing.

Upvotes: 3

Related Questions