在xml中注入属性失败(spring-ws配置) [英] injection of property in xml fails (spring-ws config)

查看:111
本文介绍了在xml中注入属性失败(spring-ws配置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring-WS,并具有以下spring-ws-servlet.xml文件. 注入defaultURI和marshaller无效,因为当我在服务的客户端中访问该方法时,这些属性为null. 发生的情况是使用正确的值调用了setter,但是在客户端的getSum()方法中,这些值均为null.有什么问题吗?

i'm using Spring-WS and have the following spring-ws-servlet.xml file. The injection of defaultURI and marshaller doesn't work because when i get to the method in the client of the service these properties are null. What happens is that the setters are being called with correct values, but in the method of the client getSum() these values are null. What could be wrong?

<?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:sws="http://www.springframework.org/schema/web-services"
   xmlns:oxm="http://www.springframework.org/schema/oxm"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

<context:component-scan base-package="com.coral.project.endpoints"/>

<sws:annotation-driven />

<sws:dynamic-wsdl id="test" portTypeName="TestCase" locationUri="/testService/"
                  targetNamespace="http://www.example.org/schemasDef/test/definitions">
    <sws:xsd location="/WEB-INF/schemasDef/test.xsd"/>
</sws:dynamic-wsdl>

<bean id="springWSClient" class="com.coral.project.endpoints.SpringWSClient">
    <property name="defaultUri" value="http://localhost:8080/parking/springServices/testService"/>
    <property name="marshaller" ref="marshaller" />
    <property name="unmarshaller" ref="marshaller" />
</bean>

<oxm:jaxb2-marshaller id="marshaller">
    <oxm:class-to-be-bound name="com.coral.project.entity.Street"/>
</oxm:jaxb2-marshaller>
</beans>

我得到了例外:

在组件上调用encodeEnd时发生异常:{Component-Path:[类:org.ajax4jsf.component.AjaxViewRoot,ViewId:/appealConversionStatusReport.jsp] [类:org.apache.myfaces.custom.div.Div,Id: j_id_jsp_1406177460_4] [类别:com.exadel.htmLib.components.UITable,Id:j_id_jsp_1406177460_5] [类别:com.exadel.htmLib.components.UITbody,Id:j_id_jsp_1406177460_6] [类别:org.apache.myfaces. .HtmlInputHidden,Id:j_id_jsp_546672833_0]}

Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /appealConversionStatusReport.jsp][Class: org.apache.myfaces.custom.div.Div,Id: j_id_jsp_1406177460_4][Class: com.exadel.htmLib.components.UITable,Id: j_id_jsp_1406177460_5][Class: com.exadel.htmLib.components.UITbody,Id: j_id_jsp_1406177460_6][Class: org.apache.myfaces.component.html.ext.HtmlInputHidden,Id: j_id_jsp_546672833_0]}

起因: java.lang.IllegalStateException-未注册封送处理程序.检查WebServiceTemplate的配置.

Caused by: java.lang.IllegalStateException - No marshaller registered. Check configuration of WebServiceTemplate.

客户:

package com.coral.project.endpoints;

import java.io.IOException;
import java.io.StringWriter;

import javax.inject.Inject;
import javax.xml.soap.SOAPException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;

import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.xml.transform.StringSource;

import com.coral.project.dao.ifc.StreetDao;
import com.coral.project.entity.Street;
import com.coral.utils.SpringUtils;

public class SpringWSClient extends WebServiceGatewaySupport {

public void getSum() throws SOAPException, IOException, TransformerException {
    StreetDao streetDao = SpringUtils.getBean(StreetDao.class);
    Street street = streetDao.findById(1);

    getWebServiceTemplate().marshalSendAndReceive(
    "http://localhost:8080/parking/springServices/testService",street);

}
}

推荐答案

您是否在代码中new正在使用SpringWSClient实例?

Are you new'ing the SpringWSClient instance in your code?

此外,对于streetDao,您不需要使用SpringUtils.getBean.而是应使用@Autowired(或@Resource)注释的字段.

Also, for the streetDao, you shouldn't need to use SpringUtils.getBean. Instead, it should be a field annotated with @Autowired (or @Resource).

这篇关于在xml中注入属性失败(spring-ws配置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆