I try communicate my Angular Frontend with my Java/Spring Boot Backend. But the terminal show me this error:
[HPM] Error occurred while trying to proxy request /api/dados from localhost:4500 to http:/localhost:8080 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Here is my exemple.service.ts (Angular) code. Here I request the data:
import {Injectable} from "@angular/core";
import {Http, Response} from "@angular/http";
import 'rxjs/Rx';
@Injectable()
export class ExService{
constructor(private http: Http){
}
getName(){
return this.http.get("/api/dados").map(
(response: Response) =>{
return response.json();
}
);
}
}
And here is my exemple.java (Java code). It is responsible to send data:
package com.lucas.bef.Envia;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/dados")
public class Dados {
String teste;
public Dados(){
this.teste = "LUCAS";
}
public void setNome(String nome){
this.teste = nome;
}
@GetMapping( value = {"","/"})
public String getNome(){
return teste;
}
}
If I start the Spring Application... The terminal show me one message Tomcat start in 8080 port.
I create a configuration proxy file (proxy-conf.json) like this:
{
"/api":{
"target": "http:/localhost:8080",
"secure": false
}
}
Please someone help me. I need do this. Is very Important. Thanks!