我有春天的背景,非常简单
<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时,它没关系,我可以在我的帮助下得到我的bean
appContext.getBean("clientService")
有人能告诉我我的错误在哪里吗?
答案 0 :(得分:0)
@Autowired
WebServiceInterface clientService;
必须位于由
所涵盖的包下的类中<context:component-scan base-package="by.test"/>
答案 1 :(得分:0)
您必须在ApplicationContext.xml中添加此配置:
<context:annotation-config/>
答案 2 :(得分:0)
在您的弹出上下文文件中添加<mvc:annotation-driven />
根据您的Spring版本添加schemaLocation
(对我而言是4.x)并将基础包更改为“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>