Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带Spring和AOP的RMI_Java_Spring_Rmi_Spring Aop - Fatal编程技术网

Java 带Spring和AOP的RMI

Java 带Spring和AOP的RMI,java,spring,rmi,spring-aop,Java,Spring,Rmi,Spring Aop,我正在尝试用RMI和AOP实现一个Spring应用程序。我的服务器组件有问题。如果我要公开的服务接口没有扩展Remote,并且这些方法没有抛出RemoteException,我将得到错误: UnknownAdviceTypeException: Advice object [org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor@1f90645] is

我正在尝试用RMI和AOP实现一个Spring应用程序。我的服务器组件有问题。如果我要公开的服务接口没有扩展
Remote
,并且这些方法没有抛出
RemoteException
,我将得到错误:

UnknownAdviceTypeException: Advice object [org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor@1f90645] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]
如果接口扩展了
Remote
,那么它可以正常启动,依此类推。 我的
application.xml
只声明了一个bean:

<bean id="testService" class="org.springframework.remoting.rmi.RmiServiceExporter">
    <property name="serviceName" value="TestService" />
    <property name="service" ref="testServiceImpl"/>
    <property name="serviceInterface"
        value="xxx.service.TestService" />
</bean>

我遵循这一点,但去上面的错误。如果你能帮助我,我将非常高兴。如果我在没有RMI的情况下运行JUnit测试,它会正常工作

我找到了它抛出错误的原因。这是因为我将
默认自动连线设置为
按类型
,但是
RmiServiceExporter
应该有
autowire=no

不要在接口上放置
@Transactional
,这将导致问题。把它放在你的实现上。通过此设置,您现在有了一个代理的代理,这是由于。@M.Deinum,但是
@Transactinal
没有为类中的所有方法打开事务吗?如果是,它还将为不需要的方法打开一个事务。我在impl上用
@Transactional
对它进行了测试,我仍然得到了关于advice的错误,不管它是否在接口上,它仍然会出错,并且它将只应用于公共方法(应该是您的接口方法).在我的接口中,我只有需要db访问的方法,在我的impl中也有一些不需要的方法(getter和setter(public))。如果它在接口上,为什么它会为没有db访问权限的事务打开一个事务呢?假设getter/setter(我想说不应该在那里)可能在安装过程中被调用,而代理还不存在,因此不会打开一个tx。接下来,您不应该将这些注释放在接口上,继承不受支持的原因是,Spring为此使用了一种变通方法。如果它应该是事务性的,那么应该是实现细节而不是规范细节。
<bean class="xxx.start.Client">
    <property name="testService" ref="testService"/>
</bean>

<bean id="testService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    <property name="serviceUrl" value="rmi://localhost:1099/TestService"/>
    <property name="serviceInterface" value="xxx.service.TestService"/>
</bean>