In my Spring Boot app there are a jpa/hibernate class for persistance and a service for business logic using jpa directly. When I test the app whith JUnit, service works properly but when I use it inside a Soap WS it throws an unknown exception. The WS code is the next:
package sample.ws.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebParam.Mode;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import sample.ws.model.Student;
@WebService(targetNamespace = "http://service.ws.sample/", name = "StudentWS")
@SOAPBinding(style=Style.RPC, use=Use.LITERAL)
public interface StudentWS {
@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "getStudentByIdRequest",
targetNamespace = "http://service.ws.sample/",
className = "java.lang.Long")
@WebMethod(action = "urn:GetStudentById")
@ResponseWrapper(localName = "getStudentByIdResponse",
targetNamespace = "http://service.ws.sample/",
className = "sample.ws.model.Student")
public Student getStudentById(@WebParam(name = "id", targetNamespace = "", mode= Mode.IN) Long id);
}
package sample.ws.service;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sample.ws.bussines.StudentService;
import sample.ws.model.Student;
@javax.jws.WebService(serviceName = "StudentWebService", portName = "StudentPort", targetNamespace = "http://service.ws.sample/",
endpointInterface = "sample.ws.service.StudentWS")
public class StudentWSImpl implements StudentWS {
private static Logger logger = LoggerFactory.getLogger(StudentWSImpl.class);
@Autowired
private StudentService studentService;
public Student getStudentById(Long id) {
Student st = studentService.getStudentById(id);
logger.info(student.toString());
return student;
}
}
SoapUI reported error:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
And log contents:
2018-09-06 15:45:09.816[0;39m [33m WARN[0;39m [35m28024[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36mo.a.cxf.phase.PhaseInterceptorChain [0;39m [2m:[0;39m Application {http://service.ws.sample/}StudentWebService#{http://service.ws.sample}getStudentById has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: null
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) ~[cxf-core-3.2.6.jar:3.2.6]
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:267) ~[cxf-rt-frontend-jaxws-3.2.6.jar:3.2.6]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) ~[cxf-core-3.2.6.jar:3.2.6]
The problem was fixed by using @Autowired annotation. I changed it by @Resource and all is working properly. Now I am trying to know what is the difference between both annotations in that context. More specifically, in StudentWSImpl implementation class, there was a call to
@Autowired
private StudentService studentService;
but now appears something like that:
@Resource
private StudentService studentService;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.