vendredi 20 février 2015

How do I autowire my webservices client in my WAR application (using Spring)?

I’m using Maven 3.0.3, CXF 2.7.15, and Spring 3.2.11.RELEASE. Using the JAX-WS Maven plugin, web service client classes are auto-generated, which include the below



package org.myproject.bsorg;


/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.3-b02-
* Generated source version: 2.1
*
*/
@WebService(name = "OrganizationWebService", targetNamespace = "http://ift.tt/1FCH154")
@XmlSeeAlso({
ObjectFactory.class
})
public interface OrganizationWebService {


Then I have my own service class, in which I try and reference the above through auto wiring …



package org.mainco.subco.myproject.service;



@Service("orgWsdlSvc")
public class OrgWsdlServiceImpl implements OrgWsdlService
{


@Autowired
private OrganizationWebService m_ows;


When I deploy my WAR file, I get the error



09:20:17,846 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-14) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orgWsdlSvc': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.mainco.bsorg.OrganizationWebService org.mainco.subco.myproject.service.OrgWsdlServiceImpl.m_ows; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.mainco.bsorg.OrganizationWebService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:290) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1148) [spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]


But I’m confused about how to properly autowire things in my web.xml and accompanying context files. In my WEB-INF/web.xml, I have



<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/META-INF/spring/applicationContext-myproject.xml,
classpath:/META-INF/spring/infrastructure.xml
</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>myproject.webapp</param-value>
</context-param>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


In my WEB-INF/dispatcher-servlet.xml file I have



<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />

<context:component-scan base-package="org.mainco" />

<!-- Define spring bean for use with this app. -->
<bean id="localPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:application.properties</value>
</property>
</bean>

<!-- Define application properties for use in Spring classes -->
<util:properties id="applicationProperties" location="classpath:application.properties" />

<tx:annotation-driven />

<jaxws:client id="orgWebServiceClient"
serviceClass="org.mainco.bsorg.OrganizationWebService"
address="${wsdl.url}"
/>


and in my “applicationContext-myproject.xml”, I have



<util:properties id="applicationProperties" location="classpath:application.properties" />
<util:properties id="coreProperties" location="classpath:core.properties" />

<context:component-scan base-package="org.mainco.subco" />
<context:component-scan base-package="org.mainco.bsorg" />

<bean id="sessionTimeoutInSeconds" class="java.lang.Long">
<constructor-arg>
<value>3600</value>
</constructor-arg>
</bean>

<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />

<!-- Define spring bean for use with this app. -->
<bean id="localPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:application.properties</value>
</property>
</bean>

<bean id="assert" class="org.mainco.subco.util.Assert" factory-method="createInstance" />

<http-conf:conduit name="https://.*">
<http-conf:tlsClientParameters secureSocketProtocol="TLSv1" disableCNCheck="true">
<sec:trustManagers>
<sec:keyStore type="JKS" password="${key.store.password}" resource="${key.store.file}" />
</sec:trustManagers>
<sec:keyManagers keyPassword="${key.manager.password}">
<sec:keyStore type="pkcs12" password="${private.key.password}" resource="${private.key.file}" />
</sec:keyManagers>
</http-conf:tlsClientParameters>
</http-conf:conduit>


What do I need to do so I can autowire my web services client?


Aucun commentaire:

Enregistrer un commentaire