Spring Boot CXF服务引发JPA异常

问题描述 投票:-1回答:1

在我的Spring Boot应用程序中,有一个jpa / hibernate类用于持久性和直接使用jpa的业务逻辑服务。当我使用JUnit测试应用程序时,服务正常工作但是当我在Soap WS中使用它时会抛出一个未知的异常。 WS代码是下一个:

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报告错误:

<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>

并记录内容:

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]
spring jpa cxf
1个回答
0
投票

使用@Autowired注释修复了该问题。我通过@Resource更改了它,一切正常。现在我试图了解该上下文中两个注释之间的区别。更具体地说,在StudentWSImpl实现类中,有一个调用

@Autowired
 private StudentService studentService;

但现在看起来像这样:

@Resource
 private StudentService studentService;
© www.soinside.com 2019 - 2024. All rights reserved.