我收到一个错误,我无法弄清楚它与Spring WebserviceTemplate有什么关系。
这里是类定义:(有趣的部分是如果我删除@Service注释,它工作正常。)
@Service
public class PTSWebServicesClientStubImpl implements PTSWebServicesStub
{
@Autowired
@Qualifier("PTS")
private WebServiceTemplate ptsWebServiceTemplate;
.....//
}
这是xml配置:
<bean id="ptsWebServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<qualifier value="PTS" />
<constructor-arg ref="messageFactory" />
<property name="marshaller" ref="ptsJaxbMarshaller" />
<property name="unmarshaller" ref="ptsJaxbMarshaller" />
<property name="interceptors">
<list>
<ref bean="loggingInterceptor" />
</list>
</property>
</bean>
当我尝试部署或从Junit测试中调用它时,我收到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.ws.client.core.WebServiceTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=PTS)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 100 more
答案 0 :(得分:1)
如果对属性和Spring bean id使用相同的名称,则不需要限定符注释。
如果您仍然想要,请使用“ptsWebServiceTemplate”作为限定符注释的属性值。
XML中的限定符元素用于自定义限定符注释类型(您自己的注释使用@Qualifier本身注释)