java.lang.NoSuchMethodException:$ Proxy205.dispatch(int,my.package.beans.AdapterHeader,my.package.beans.AdapterInfo)

时间:2012-03-17 10:49:35

标签: java spring osgi

有没有人经历过这个?

在服务器端,在我的OSGi应用程序中,我正在导出服务。这是spring文件代码:

    <!-- RMI SERVICE EXPORT -->
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
    <property name="serviceName" value="IntegrationRemoteService" />
    <property name="service" ref="integrationExecutor" />
    <property name="serviceInterface" value="my.package.services.IntegrationService" />
    <property name="registryPort" value="$system{integration.port}" />
</bean>

<!-- INTEGRATION EXECUTOR -->
<bean id="integrationExecutor" class="my.package.engine.IntegrationServiceExecutor">
    <property name="integrationServiceImpl" ref="integrationEngine" />      
</bean>

我的IntegrationServiceExecutor类扩展了IntegrationService接口并实现了方法:

public class IntegrationServiceExecutor implements IntegrationService {
...
@Override
public GenericResult dispatch(int serviceCode, AdapterHeader adapterHeader,    AdapterInfo  adapterInfo) {

IntegrationService接口在另一个组件中定义,同一个组件在我的.war中用于客户端。在该组件中,我还通过我的.war

实现了远程请求
...
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
...

    public class GenericRmiFactory implements RemoteConnectionFactory {

private ProxyFactory proxyFactory;

public GenericRmiFactory(ServerTransport transport) throws ClassCastException, IllegalFormatException {
    RmiServerTransport rmiTransport = (RmiServerTransport) transport;

    RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();

    rmiProxyFactoryBean.setLookupStubOnStartup( false );
    rmiProxyFactoryBean.setCacheStub( false );
    rmiProxyFactoryBean.setRefreshStubOnConnectFailure( true );
    rmiProxyFactoryBean.setServiceUrl(String.format("rmi://%s:%s/%s", rmiTransport.getHostname(), rmiTransport.getPort(), rmiTransport.getServiceName() ));
    rmiProxyFactoryBean.setServiceInterface(rmiTransport.getRemoteInterface());
    rmiProxyFactoryBean.afterPropertiesSet();

    this.proxyFactory = new ProxyFactory(rmiTransport.getRemoteInterface(), rmiProxyFactoryBean);
}

private ProxyFactory getproxyFactory() {
    return proxyFactory;
}

@Override
public Object getRemoteService() {
    return getproxyFactory().getProxy();
}
}

我以这种方式呼叫远程服务:

    ...
    IntegrationService integrationService = (IntegrationService) getGenericRemoteFactory().getRemoteService();
integrationService.dispatch(myInt, myAdapterHeader, myAdapterInfo);
...

最后一条语句抛出异常:

Invocation of method [public abstract my.package.result.GenericResult my.package.services.IntegrationService.dispatch(int,my.package.beans.AdapterHeader,my.package.beans.AdapterInfo)] failed in RMI service [rmi://127.0.0.1:2260/IntegrationRemoteService]; nested exception is java.lang.NoSuchMethodException: $Proxy205.dispatch(int, my.package.beans.AdapterHeader, my.package.beans.AdapterInfo)

这里有什么我想念的吗? 提前致谢, 卡伦

1 个答案:

答案 0 :(得分:1)

我之前见过这个。您必须向接口方法添加“throws RemoteException”。客户端抛出NoSuchMethodException,但它确实抱怨缺少RemoteException。