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

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

该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

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>

注意:,此方法有效,但以上操作仍然失败
<bean id="proxied" class="org.springframework.aop.framework.ProxyFactory" />

线程[main](已挂起(进入ProxyFactory中的方法))
ProxyFactory。()行:40
NativeConstructorAccessorImpl.newInstance0(Constructor,Object [])行:不可用[本机方法]
NativeConstructorAccessorImpl.newInstance(Object [])行:39
DelegatingConstructorAccessorImpl.newInstance(Object [])行:27
Constructor.newInstance(Object ...)行:494

最佳答案

请再次检查您是否也具有以下依赖关系:

  • aopalliance.jar
  • spring-core.jar
  • NoClassDefFoundError并未说找不到ProxyFactory类-确实已经找到了,但是缺少了某些依赖项。

    07-27 13:39