Java RMI方式调用问题 but was actually of type [$Proxy7]

本文分析了Spring框架中出现的依赖注入错误案例,探讨了配置文件与Java代码间不匹配导致的问题,具体表现为期望类型与实际类型不符。通过对比正确的依赖注入方式,指出了修正方法。


配置文件不变:

    <!-- 分类 -->
    <bean id="commoCategoryServComponent" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl" value="${ecos_commodity_remote.url}/ICommoCategoryServComponent"/>
        <property name="serviceInterface" value="org.lazicats.ecos.commodity.service.component.ICommoCategoryServComponent"/>
    </bean>
    <!-- 运营分类 -->
     <bean id="categoryServComponent" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl" value="${ecos_commodity_remote.url}/IOperatingCategoryServComponent"/>
        <property name="serviceInterface" value="org.lazicats.ecos.commodity.service.component.IOperatingCategoryServComponent"/>
    </bean>

引用的java变动:

   
    @Resource
    private ICommoCategoryServComponent categoryServComponent;
    but was actually of type [$Proxy7]
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productStockController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productStockViewComponentImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'categoryServComponent' must be of type [org.lazicats.ecos.commodity.service.component.ICommoCategoryServComponent], but was actually of type [$Proxy7]
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    下面就OK
    @Resource
    private ICommoCategoryServComponent commoCategoryServComponent;
    
   



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值