配置文件不变:
<!-- 分类 -->
<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;

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

被折叠的 条评论
为什么被折叠?



