-3

I am building a spring boot application, which has multiple micro-services which are being used by one main service. Services are created as maven modules and I am using intelliJ IDEA 15 with trial period. Now when I am trying to run the service I am getting the following error. I think my tomcat server is not running but I am not getting how to check and if this is the problem then how to resolve. I have included tomcat dependency in pom.xml.

the class which I am running is this->

AlpsWsApplication.java

@SpringBootApplication
public class AlpsWsApplication {
    private static final Logger logger = LoggerFactory
            .getLogger(AlpsWsApplication.class);
    public static void main(String[] args) {
        SpringApplication.run(AlpsWsApplication.class, args);
    }
}

with this there are hibernate, Apache qpid configuration files.

Stack trace:

ERROR 10 Mar 2016 14:01:10,185 [main] org.springframework.boot.SpringApplication: Application startup failed
com.ecwid.consul.transport.TransportException: java.net.ConnectException: Connection refused
    at com.ecwid.consul.transport.DefaultHttpTransport.executeRequest(DefaultHttpTransport.java:87)
    at com.ecwid.consul.transport.DefaultHttpTransport.makeGetRequest(DefaultHttpTransport.java:46)
    at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:66)
    at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:135)
    at com.ecwid.consul.v1.kv.KeyValueConsulClient.getKVValues(KeyValueConsulClient.java:128)
    at com.ecwid.consul.v1.ConsulClient.getKVValues(ConsulClient.java:346)
    at org.springframework.cloud.consul.config.ConsulPropertySource.init(ConsulPropertySource.java:57)
    at org.springframework.cloud.consul.config.ConsulPropertySourceLocator.locate(ConsulPropertySourceLocator.java:70)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:88)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:628)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:328)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101)
    at com.alps.AlpsWsApplication.main(AlpsWsApplication.java:13)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
    at com.ecwid.consul.transport.DefaultHttpTransport.executeRequest(DefaultHttpTransport.java:71)
    ... 14 more
Rohan Singh Dhaka
  • 173
  • 2
  • 8
  • 33
  • 3
    Errors without code is as useless as code without errors. – ChiefTwoPencils Mar 10 '16 at 08:44
  • @ChiefTwoPencils added some more information. There are so many files I am not able to understand which file to put. There are web controller classes which takes API calls, hibernate and Apache qpid configuration files and many more. – Rohan Singh Dhaka Mar 10 '16 at 09:00
  • You can **ping** the server ip to check if the server is running or check if the server process is running (on linux **ps -e**) if it is on your local computer. Because this **java.net.ConnectException: Connection refused** is the error cause it is very likely that this is a connection to server problem, i.e. firewall – ralf htp Mar 10 '16 at 09:05
  • check what ports your services use on the server check the firewall for these ports – ralf htp Mar 10 '16 at 09:08
  • @ralfhtp I am using mac and i have turned off my firewall. The application is running on 8080 port. Apache qpid is running on 5672 port and listening to 8081 port. – Rohan Singh Dhaka Mar 10 '16 at 09:11
  • The exception message is clear enough. What do you not understand about it? – Raedwald Mar 10 '16 at 09:39
  • @Raedwald According to me the server is not running. I don't know whether it is right or not. – Rohan Singh Dhaka Mar 10 '16 at 14:17

2 Answers2

0

'Connection refused' has exactly one meaning: the target host was up and there was nothing listening at the specified port. So either you didn't start the service or you got the IP address or port wrong.

And specifically contrary to the comments here:

  • it is not a 'host down' condition
  • it is not a firewall problem
  • it is not a network connectivity problem (ping).
user207421
  • 305,947
  • 44
  • 307
  • 483
  • According to this blog java.net.ConnctException is also thrown when server down or firewall up: http://javarevisited.blogspot.de/2013/02/java-net-ConnectException-Connection-refused.html – ralf htp Mar 10 '16 at 09:41
  • @ralfhtp Your link is wrong. You can't cite arbitrary Internet rubbish. 'Server down' would cause a connect timeout, if you mean 'host down', as would a firewall port block. If by 'server down' you mean 'application not running', you're agreeing with me. – user207421 Mar 10 '16 at 09:48
  • Is correct java.net.ConnectException **connection timed out** is thrown when server is down and firewall is up not **connection refused**. okay then i delete the link... The problem then may be that Tomcat is not listening on the port that the service tries to bind to (application not running) – ralf htp Mar 10 '16 at 10:02
  • @ralfhtp There is no 'may be' about it. The problem *is* that Tomcat isn't listening on that IP:port, and neither is anything else. No other possibility. – user207421 Mar 10 '16 at 10:08
0

The problem was that I have included spring cloud consul dependency in the pom.xml file but didn't start the server.

Rohan Singh Dhaka
  • 173
  • 2
  • 8
  • 33