Spring Boot CXF服务将JPA引发异常

时间:2018-09-05 17:45:47

标签: spring jpa cxf

在我的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]

1 个答案:

答案 0 :(得分:0)

通过使用@Autowired批注解决了该问题。我通过@Resource进行了更改,并且一切正常。现在,我想知道在此上下文中两个注释之间的区别是什么。 更具体地说,在StudentWSImpl实现类中,有一个调用

;(function(){
//function id(v){ return document.getElementById(v); }
function loadbar() {
    var ovrl = document.getElementById("loadCont"),
        prog = document.getElementById("loadPct"),
        stat = document.getElementById("progstat"),
        img = document.images,
        c = 0;

    var  tot = img.length;
    if(tot == 0) return doneLoading();
    if(!prog){return doneLoading();}

    function imgLoaded(){
        c += 1;
        //console.log(c);
        var perc = ((100/tot*c) << 0)-100;
        perc = perc*-1;
        perc = perc + '%';
        prog.style.height = perc;
        //stat.innerHTML = "Loading "+ perc;
        if(c===tot) return doneLoading();
        //console.log(perc);
    }
    function doneLoading(){
        //ovrl.style.opacity = 0;
        var d = document.getElementById("body");
        d.className += " loaded";
        setTimeout(function(){ 
            //ovrl.style.display = "none";
        }, 1200);
    }
    for(var i=0; i<tot; i++) {
        var tImg     = new Image();
        tImg.onload  = imgLoaded;
        tImg.onerror = imgLoaded;
        tImg.src     = img[i].src;
    }    
}
document.addEventListener('DOMContentLoaded', loadbar, false);
}());

但现在出现类似的内容:

printf