4

我试图使用 Spring 3.1 配置文件和 EasyMock 来模拟 HttpClient 实现,但 Spring 容器抱怨它找不到正确类型的 bean。我是否配置了错误的模拟?如果我用正确注入的实际实现替换 EasyMock bean,那么 EasyMock 方法似乎没有创建正确类型的 bean。非常感谢所有帮助!

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.http.client.HttpClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856)

<beans profile="development,developmentthomas,test,integration,webtest,accept">
    <bean id="httpClient" class="org.easymock.EasyMock" factory-method="createMock">
        <constructor-arg value="org.apache.http.client.HttpClient" />
    </bean>
</beans>

<beans profile="thomasciserver,testserverlocaloleg,testservercioleg,preprod,production,testservercithomas,testserverlocalthomas,localthomasclean,testserver,productionthomas">
    <bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient"/>
</beans>
4

2 回答 2

0

请参阅弹簧测试。它有 org.springframework.mock.http.client.MockClientHttpRequest。org.springframework.mock 包有一大堆东西可以让你免于重新发明轮子。

于 2013-05-03T14:28:50.727 回答
0

我认为问题在于工厂方法。

看看这篇文章Autowiring of beans generated by EasyMock factory-method? 我认为这会解决你的问题

于 2013-05-02T15:34:59.853 回答