var restTemplate = new TestRestTemplate();
var actual = restTemplate.getForEntity(new URI("http://localhost:8080/foo"), PatientViewDto.class);
When I try to use this method an Exception occurs
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/foo": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
CodePudding user response:
This exception (Connection refused) means that there is no service listening on the localhost port 8080.
review this:
- Check IP and port.
- Server is up and running.
CodePudding user response:
Check if @SpringBootTest
is configured to use a random port. If it is the case spring-boot will start the app in a random port other than 8080.
Remove the random port config @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
then the app will start on port 8080 (or the port configured by server.port
)