【问题标题】:RMI with Spring and AOP带有 Spring 和 AOP 的 RMI
【发布时间】:2017-04-26 07:09:27
【问题描述】:

我正在尝试使用 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>

我的接口只有@Transactional注解,而实现有@Service注解。

在我的客户中,我也遇到了错误。在这里,我收到一个非唯一 bean 的错误:找到 bean testServicetestServiceImpl。我的 client.xml 看起来像这样:

<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>

我关注了这个guide,但出现了上面的错误。如果你能帮助我,我会很高兴。如果我在没有 RMI 的情况下运行我的 JUnit 测试,它工作正常

【问题讨论】:

  • 不要将@Transactional 放在接口上,这会导致问题。把它放在你的实现上。有了这个设置,你现在有了一个代理的代理。
  • @M.Deinum 但@Transactinal 不会为类中的所有方法打开事务吗?如果是的话,它也会为不需要的方法打开一个事务。我在 impl 上使用@Transactional 对其进行了测试,但我仍然收到有关建议的错误
  • 不管它是否在接口上,它仍然有效,它只会应用于公共方法(应该只是你的接口方法)。
  • 在我的界面中,我只有需要数据库访问的方法,而在我的 impl 中也有一些没有(getter 和 setter(public))。如果它在接口上,为什么它会为没有数据库访问权限的人打开一个事务?
  • 假设在设置期间可能会调用 getter/setter(我会说不应该存在),但代理尚不存在,因此不会打开 tx。除此之外,您不应该将这些注释放在接口上,由于某种原因不支持继承,Spring为此使用了一种解决方法。如果它应该是事务性的,则应该是实现细节而不是规范细节。

标签: java spring rmi spring-aop


【解决方案1】:

我发现它为什么会抛出错误。这是因为我将default-autowiring 设置为byType,但RmiServiceExporter 应该有autowire=no

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2020-09-17
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    相关资源
    最近更新 更多