Search code examples
springspring-wswebservicetemplate

Spring WebserviceTemplate not being registered


I am getting an error which i am not able to figure out what it is for related to Spring WebserviceTemplate.

here is the Class definition: (Interesting part is if i Remove the @Service annotation, it works fine.)

@Service
public class PTSWebServicesClientStubImpl implements PTSWebServicesStub
{
    @Autowired
    @Qualifier("PTS")
    private WebServiceTemplate ptsWebServiceTemplate;
 .....//
 }

here is the xml configuration:

<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>

When i try to deploy this or call it from Junit test, i get the below error:

  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

Solution

  • You don't need the Qualifier annotation if you use the same name for the attribute and for the Spring bean id.

    If you still want to, use "ptsWebServiceTemplate" for the attribute value of the Qualifier annotation.

    The qualifier element in the XML is intended for custom Qualifier annotation types (your own annotation annotated with @Qualifier itself)