I have created a REST API example in Eclipse using Spring Boot.
When I access API using http://localhost:8080/getInfo
then it works, but if I am accessing the same API from external client using IP address http://<IP address>:8080/getInfo
then it gives error - Failed to connect to
How to access API using IP address OR Domain Name?
Asked
Active
Viewed 2,076 times
4

Mrunal
- 111
- 1
- 2
- 11
-
how you start java app ? – Thanh Nguyen Van Sep 10 '18 at 07:14
-
Are you trying to access your REST service through a machine which is connected to the network where your server machine is in? if not can you explain the exact scenario you are trying to achieve? – Damith Sep 10 '18 at 07:15
-
1From the external client, can you successfully ping your IP ? – Thoomas Sep 10 '18 at 07:15
-
Are you running your server in local machine or cloud? – nitinsridar Sep 10 '18 at 07:17
-
Which application is your external client – Machhindra Neupane Sep 10 '18 at 07:21
-
Possible duplicate of [How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?](https://stackoverflow.com/questions/23946369/how-to-configure-embedded-tomcat-integrated-with-spring-to-listen-requests-to-ip) – g00glen00b Sep 10 '18 at 07:24
-
Can you please add what you have tried? Have you checked your firewall? Can you ping the host from an external client? What OS are you running? – Reg Sep 10 '18 at 07:33
-
@ThanhNguyenVan I run the application using command - mvn spring-boot:run – Mrunal Sep 10 '18 at 08:42
-
@Damith yes. machine is in the same network. And I can also ping my IP from that machine. – Mrunal Sep 10 '18 at 08:44
-
@Nithin Running on local machine, in same network – Mrunal Sep 10 '18 at 08:45
-
can you provide the exact error that you are getting? – Damith Sep 10 '18 at 08:51
-
Getting error "Failed to connect to
" – Mrunal Sep 10 '18 at 08:57
1 Answers
1
If you want to specify different server address other than localhost or any other server configuration like port, error controller or timeout settings, you can do it using server default properties in application.properties. Spring will automatically load embedded tomcat configurations from the application.properties file. For different server address use.
server.address= # Network address to which the server should bind.
In you application.properties.
For other server configurations, have a look at : Spring Common Properties

Rezwan
- 1,203
- 1
- 7
- 22