[英]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.