为什么/如何得到错误:NoClassDefFoundError:org / springframework / aop / framework / ProxyFactory

时间:2011-02-16 19:41:32

标签: java proxy rmi spring-aop

目标:启动支持远程访问方法调用的服务器。

在创建所有服务之前,应用程序不会失败。

jar位于target / lib目录中。

父pom具有依赖关系:

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

注意:我可以创建一个类型为:org.springframework.aop.framework.ProxyFactory

的spring bean

堆栈追踪:

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

应用场境的服务的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>

注意:这样可行,但上述内容仍然失败

<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 

3 个答案:

答案 0 :(得分:3)

请仔细检查您是否还有以下依赖项:

  • aopalliance.jar
  • 弹簧core.jar添加

NoClassDefFoundError并没有说它找不到ProxyFactory类 - 事实上,它已被发现,但它的某些依赖项缺失了。

答案 1 :(得分:0)

这是一个日食环境问题 我使用SysDeo Tomcat插件 在Window > Preferences > Tomcat > Source Path下,我必须取消选中除客户端和服务器项目之外的所有项目。

答案 2 :(得分:0)

请将spring-aop-X.X.X.jar添加到与您正在使用的spring版本jar相关的项目库中。 然后问题就会得到解决 如果您不使用适当版本的jar,则会继续出现此错误。

如果在spring中添加不同版本的jar,则该功能可能无效。请确保使用相同版本的最佳开发人员实践。

谢谢!