我陷入了这个问题,不知道我做错了什么。 我正在消费SOAPWS&当我打电话给那个网络服务时,它会给出异常&我检查了WebServiceTemplate对象是null,但是一旦它在构造函数中初始化了。 它进入sendNpsReminder操作时,它设置为null。不知道为什么。有人可以请帮助。
的pom.xml
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
JavaClass:
public class ManageCustomerService extends WebServiceGatewaySupport {
private static final CDLoggerInterface logger = CDLogger
.getLogger(ManageCustomerService.class);
private WebServiceTemplate manageContactsWSTemplate;
public ManageCustomerService()
{
}
public ManageCustomerService(WebServiceTemplate manageContactsWSTemplateObj) {
this.manageContactsWSTemplate = manageContactsWSTemplateObj;
logger.debug("Constructor Setting the WebServieTemplte "+manageContactsWSTemplate);
}
public SendNPSReminderResponseType sendNpsReminder() {
logger.debug("Calling now with new JOB="+manageContactsWSTemplate);
SendNPSReminderRequestType sendNPSReminderRequest = new SendNPSReminderRequestType();
Contact Contact = new Contact();
Contact.setPhone(new BigInteger("XYZ"));
sendNPSReminderRequest.setCountryCode(ABC);
sendNPSReminderRequest.setContact(Contact);
sendNPSReminderRequest.setCustomerNumber("23239220");
if(manageContactsWSTemplate != null)
{
SendNPSReminderResponseType response = (SendNPSReminderResponseType)manageContactsWSTemplate.marshalSendAndReceive("http://tsi-vip-osbdev.canaldigital.com:7111//GSD_ManageCustomer_v2/ProxyService/Proxy/GSD_ManageCustomer_PS?wsdl", sendNPSReminderRequest, new SoapActionCallback("http://canaldigital.com/tsi/Schema/GSD/GSD_ManageCustomer/v2/GSD_ManageCustomer_SendNPSReminder"));
logger.info("Response for SendNpsReminder is : "+response.getResponseCode());
}
else{
logger.debug("manageContactsWSTemplate is null");
}
return xyz;
}
的applicationContext.xml
<oxm:jaxb2-marshaller id="manageContactMarshaller"
contextPath="packagename" />
<oxm:jaxb2-marshaller id="manageContactUnmarshaller"
contextPath="packagename" />
<bean name="manageContactsWSTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="defaultUri" value="http://tsi.com:7111/GSD_ManageCustomer_v1?WSDL" />
<property name="marshaller" ref="manageContactMarshaller" />
<property name="unmarshaller" ref="manageContactUnmarshaller" />
</bean>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
</bean>
<bean id="manageContactService" class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
<constructor-arg ref="manageContactsWSTemplate" />
</bean>
<bean id="CDCommonTasksJob"
class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
</bean>
<!-- Scheduler -->
<task:scheduled-tasks>
<task:scheduled ref="CDCommonTasksJob" method="sendNpsReminder"
cron="0 0/2 * * * *" />
</task:scheduled-tasks>
答案 0 :(得分:1)
从你的spring-context .xml看起来你正在请求同一个类的两个bean:ManageCustomerService,第一个将通过构造函数调用,并且将有一个有效的spring bean作为WebServiceTemplate,但是第二个(CDCommonTasksJob)将使用默认构造函数调用,因此对WebServiceTemplate的引用将为null。因此,在任务调度程序中,您将自动装配没有webServiceTemplate实例的bean
所以问题是,为什么要创建同一个类的两个bean?
如果您仍需要两个bean,只需替换
行 <bean id="CDCommonTasksJob"
class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
</bean>
使用:
<bean id="CDCommonTasksJob" class="com.canaldigital.tsi.managecontacts.serviceprovider.ManageCustomerService">
<constructor-arg ref="manageContactsWSTemplate" />
</bean>