HttpErrorResponse:内部服务器错误

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

我是新来的

angular 6
.

我用

spring boot
开发了一个邮政服务,当我通过
Postman
测试它时,它工作得很好,但是当我用网络浏览器测试它时,它给了我这个错误:

HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "OK", url: "http://localhost:8080/api/test/ordermiss", ok: false, …}error: {timestamp: "2019-07-10T13:35:09.083+0000", message: null, details: "uri=/api/test/ordermiss"}details: "uri=/api/test/ordermiss"message: nulltimestamp: "2019-07-10T13:35:09.083+0000"__proto__: Objectheaders: HttpHeaderslazyInit: ƒ ()lazyUpdate: nullnormalizedNames: Map(0) {}__proto__: Objectmessage: "Http failure response for http://localhost:8080/api/test/ordermiss: 500 OK"name: "HttpErrorResponse"ok: falsestatus: 500statusText: "OK"url: "http://localhost:8080/api/test/ordermiss"__proto__: HttpResponseBaseconstructor: ƒ HttpErrorResponse(init)__proto__: Object

and when I take a look to the `Spring` console it gave this warning :

2019-07-11 13:36:01.796  WARN 14404 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [java.lang.NullPointerException]

我对另一个对象使用相同的方法,但我没有收到此错误,所以,请你能帮帮我吗?

service

         constructor(private http: HttpClient) { }

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

这就是

.ts

    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();
    }

班级

angular

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

controller

  @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

   @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);                   
 }

entity

@Entity
@Table(name = "ordermission")
public class Ordermission {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String mat;

@Enumerated(EnumType.STRING)
private Typetransport type;

@Enumerated(EnumType.STRING)
private Etat etat;

@Enumerated(EnumType.STRING)
private Local depart;

@Enumerated(EnumType.STRING)
private Local dest;
@Temporal(TemporalType.DATE)
private Date datedeb;
@Temporal(TemporalType.DATE)
private Date datefin;

private Double distance;

private Long couttranp;
private Long coutheberg;

// @Formula("couttranp + coutheberg")
private Double total;
java angular hibernate spring-boot nullpointerexception
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.