[英]Spring can't autowire webservice bean defined in context
我有春天的背景,很簡單
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="by.test.**"/>
<bean id="clientService" class="by.test.WebServiceImpl"/>
</beans>
該bean是cxf Web服務的實現
public class WebServiceImpl implements WebServiceInterface{
//overriden methods
}
WebServiceInterface
是從用於Web服務的wsdl接口生成的。 當我嘗試使用類似
@Autowired
WebServiceInterface clientService;
NoSuchBeanDefinitionException
錯誤。 當我自動連接應用程序上下文並從中獲取bean時,可以,可以在appContext.getBean("clientService")
的幫助下獲取bean。有人可以告訴我我的錯誤在哪里嗎?
@Autowired
WebServiceInterface clientService;
必須位於一個類中,該類位於
<context:component-scan base-package="by.test"/>
您必須在ApplicationContext.xml中添加此配置:
<context:annotation-config/>
在您的Spring上下文文件中添加<mvc:annotation-driven />
,根據您的Spring版本(對我來說是4.x)添加schemaLocation
,並將基本包更改為“ by.test” ,如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="by.test"/>
<bean id="clientService" class="by.test.WebServiceImpl"/>
</beans>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.