HttpErrorResponse:内部服务器错误

时间:2019-07-10 14:00:33

标签: java angular hibernate spring-boot nullpointerexception

我是新手,角度为6。 我已经开发了一个带有弹簧启动的邮政服务,当我通过邮递员对其进行测试时,它可以正常工作,但是当我使用网络浏览器对其进行测试时,它给了我这个错误:

HttpErrorResponse {headers:HttpHeaders,status:500,statusText:“ OK”,url:“ http://localhost:8080/api/test/ordermiss”,ok:false,...}错误:{timestamp:“ 2019-07-10T13:35:09.083 +0000”,消息:空,详细信息:“ uri = / api / test / ordermiss”}详细信息:“ uri = / api / test / ordermiss”消息:nulltimestamp:“ 2019-07-10T13:35:09.083 + 0000” proto :对象标头:HttpHeaderslazyInit:ƒ()lazyUpdate:nullnormalizedNames:Map(0){} proto :对象消息:“ http://localhost:8080/api/test/ordermiss的Http失败响应:500 OK “名称:” HttpErrorResponse“确定:错误状态:500statusText:”确定“ URL:” http://localhost:8080/api/test/ordermiss proto :HttpResponseBaseconstructor:ƒHttpErrorResponse(init) proto :对象

当我看一下spring控制台时,它发出了这个警告:

2019-07-11 13:36:01.796警告14404 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver:已解决[java.lang.NullPointerException]

我在另一个对象上使用了相同的方法,但是我没有收到此错误,所以请您帮忙

此服务:

ul.todo#todo {
    position:relative;
}

ul.todo#completed:not(:empty) {
    position:relative;
    padding:60px 0 0 0;
    background:#000;
    opacity:0.3;
}

ul.todo#completed:not(:empty):before {
    content:'';
    width:150px;
    height:1px;
    background:#fff;
    position:absolute;
    top:30px;
    left:50%;
    margin:0 0 0 -75px;
}

这是.ts:

                constructor(private http: HttpClient) { }

           SaveOM(Om: Object): Observable<Object> {
         return this.http.post(`${this.baseUrl}`, Om);
           }

角度类:

    save() {
      this.omService.SaveOM(this.ordermission)
      .subscribe(data => console.log(data), error => console.log(error));
    this.ordermission = new Ordermission();
      }

     onSubmit() {
       this.submitted = true;
          this.save();
       }

控制器:

           export class Ordermission {
          id:number;
        mat:string;
         depart:string;
         dest:string;
      // etat:string;enum class
       // type:string;enum class
        // localisation:string;enum class
         datedeb:Date;
        datefin:Date;
         distance:number;
         couttranp:number;
         coutheberg:number;
       total:number;
        }

服务:

              @CrossOrigin(origins = "*", maxAge = 3600)
             @RestController
            @RequestMapping("/api/test")
              @PreAuthorize("hasRole('USER') or hasRole('ADMIN')")
          public class OrdermissionController {

  @Autowired private OrdermissionRepository ordermissionrep;

  @Autowired private OrderMissService orderMissService;


  @PostMapping("/ordermiss")
// @ExceptionHandler(RuntimeException.class)
    public Ordermission createOM(@Valid @RequestBody Ordermission OM) {
        return orderMissService.saveOM(OM);

    }

}

实体:

                 @Service
                public class OrderMissServiceImpl implementsOrderMissService {
                 Double var;
                 Double tot;
                 long cal;
                long cout;

  @Autowired private OrdermissionRepository ordermissionrep;


@Override
public Ordermission saveOM(Ordermission om) {
        if(om.getDepart().equals(Local.tunis) && om.getDest().equals(Local.sousse) || om.getDepart().equals(Local.sousse) && om.getDest().equals(Local.tunis)) {
        var =(double) 143;
        om.setDistance(var);
    }
    if(om.getDepart().equals(Local.tunis) && om.getDest().equals(Local.tabarka) || om.getDepart().equals(Local.tabarka) && om.getDest().equals(Local.tunis)) {
        var =(double) 175;
        om.setDistance(var);
    }


    if(om.getDepart().equals(Local.tunis) && om.getDest().equals(Local.zaghouan) || om.getDepart().equals(Local.zaghouan) && om.getDest().equals(Local.tunis)) {
        var =(double) 57;
        om.setDistance(var);
    }
    if(om.getDepart().equals(Local.tunis) && om.getDest().equals(Local.zarsis) || om.getDepart().equals(Local.zarsis) && om.getDest().equals(Local.tunis)) {
        var =(double) 544;
        om.setDistance(var);
    }

      if(om.getType().equals(Typetransport.perso)) {
          cal=(long) (om.getDistance()*2*0.08);
          om.setCouttranp(cal);
      }

      if(om.getType().equals(Typetransport.pubic)) {
          cal=(long) (om.getDistance()*2*0.375);
          om.setCouttranp(cal);
      }

     if(om.getEtat().equals(Etat.cadre)) {
         cout=(DaysBetween(om)+1)*25;
         om.setCoutheberg(cout);
     }
     if(om.getEtat().equals(Etat.non_cadre)) {
         cout=(DaysBetween(om)+1)*20;
         om.setCoutheberg(cout);
     }
     else if (om.getCoutheberg() != null && om.getCouttranp()!=null) {
        tot = (double) (om.getCoutheberg()+om.getCouttranp());
        om.setTotal(tot);
    }
    return  ordermissionrep.save(om);

1 个答案:

答案 0 :(得分:0)

错误500(内部服务器错误)有时显示CORS问题。检查您的服务器是否已正确配置为接受CORS请求