HI ALL
我试图揭露spring webservice我遇到一个问题我的服务对象没有初始化
---------------终点类--------------
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;
import com.mt.service.CalculatorService;
public abstract class AbstractCalculatorEndpoint extends AbstractMarshallingPayloadEndpoint {
protected CalculatorService calculatorService;
public void setCalcService(CalculatorService calculatorService) {
this.calculatorService = calculatorService;
}
protected abstract Object invokeInternal(Object request) throws Exception;
}
----------- AddNumberEndpoint类 ------------
package com.mt.endpoint;
import com.mt.calculator.schema.AddNumberRequest;
public class AddNumberEndpoint extends AbstractCalculatorEndpoint {
@Override
protected Object invokeInternal(Object request) throws Exception {
AddNumberRequest addNumberRequest = (AddNumberRequest) request;
if( calculatorService==null )
System.out.println("------------------- I AM NULL ------- :( ");
return calculatorService.addTwoNumber(addNumberRequest.getFirstNumber(),
addNumberRequest.getSecondNumber());
}
}
我的Servlet配置
<?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:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
<bean id="calculatorService" class="com.mt.service.CalculatorServiceImpl"
init-method="initialize" />
<bean id="Calculator"
class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schema" ref="schema" />
<property name="portTypeName" value="Calculator" />
<property name="locationUri" value="/services" />
<property name="targetNamespace" value="http://www.mt.com/calculator/schema" />
</bean>
<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="/WEB-INF/calculator.xsd" />
</bean>
<bean id="validatingInterceptor"
class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="xsdSchema" ref="schema" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
<bean id="loggingInterceptor"
class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
<oxm:jaxb2-marshaller id="marshaller"
contextPath="com.mt.calculator.schema" />
<oxm:jaxb2-marshaller id="unmarshaller"
contextPath="com.mt.calculator.schema" />
<bean id="addNumberEndpoint" class=" com.mt.endpoint.AddNumberEndpoint"
autowire="byName" />
<bean name="endpointMapping"
class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="interceptors">
<list>
<ref local="loggingInterceptor" />
<ref local="validatingInterceptor" />
</list>
</property>
<property name="mappings">
<props>
<prop key="{http://www.mt.com/calculator/schema}AddNumberRequest">
addNumberEndpoint</prop>
</props>
</property>
</bean>
<bean id="exceptionResolver"
class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
<property name="defaultFault" value="SERVER" />
<property name="exceptionMappings">
<props>
<prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
<prop key="com.mt.service.CalculatorException">SERVER</prop>
</props>
</property>
</bean>
</beans>
如果您需要任何其他信息,请告诉我
非常感谢
非常感谢
以前的例外情况已经消失我现在正在上面--------
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.Integer" as an element because it is missing an @XmlRootElement annotation]</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:1)
您按名称自动连接addNumberEndpoint
,因此Spring将查找calcService
绑定到它(因为设置者名称),但CalculatorService的ID为calculatorService
。
在setCalcService(...)
setCalculatorService(...)
更改为AbstractCalculatorEndpoint