自动装配的值保持为空?

时间:2014-09-11 08:47:26

标签: spring nullpointerexception autowired

在我的项目(Liferay Portlet)中,即时创建一个webservice-client。我在applicationContext.xml中定义了一个webServiceTemplate:

<?xml version="1.0" encoding="UTF-8"?>
<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"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
        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-3.2.xsd">

    <context:annotation-config />
    <context:component-scan base-package="be.icredit.einvoice.service, be.icredit.einvoice.webserviceTest" />


    <oxm:jaxb2-marshaller id="marshaller" contextPath="be.icredit.einvoice.proxy.customerdaoservice"/>
    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
         <property name="marshaller" ref="marshaller" /> 
         <property name="unmarshaller" ref="marshaller" /> 
        <property name="defaultUri"
            value="http://localhost:8081/ws-demo/account-balance-service" />
    </bean>

</beans>

当我在CustomerClient.java中执行testFindCustomer方法时,我在webServiceTemplate上得到一个nullpointerexception。

public class CustomerClient extends WebServiceGatewaySupport {

        @Autowired
        private WebServiceTemplate webServiceTemplate;

        private Log log = LogFactory.getLog(CustomerClient.class);

        public CustomerClient()
        {


        }
        public void testFindCustomer()
        {
            Find findCustomer = new Find();
            findCustomer.setFilter(new CustomerFilter());

            System.out.println(webServiceTemplate.getDefaultUri());
            FindResponse response = (FindResponse) webServiceTemplate.marshalSendAndReceive(findCustomer);

            ArrayList<Customer> list = (ArrayList) response.getReturn();        
            for(Customer c : list)
            {
                log.info("found");
            }

        }

这看起来非常基本,我不知道我做错了什么。 CustomerClient类位于be.icredit.einvoice.webserviceTest包中。

Nullpointerexceptions发生在System.out.println(webServiceTemplate.getDefaultUri());线。

0 个答案:

没有答案