spring-guides / gs-rest-service

Building a RESTful Web Service :: Learn how to create a RESTful web service with Spring.

Home Page:https://spring.io/guides/gs/rest-service/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to run the application

ananthashankar opened this issue · comments

I created this application in STS and followed each step given in the guide but while running the application I get below page error

http://localhost:8080/greeting

Page load failed with error: The network connection was lost.

The error is same while running the code from this repository. Could please help running the application.

screen shot 2016-08-30 at 1 52 22 am

Yes, I'm also couldn't run the application. It's always terminated, the servlet service doesn't started.
This is my console log message:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _ | \ \ \
/ )| |)| | | | | || (_| | ) ) ) )
' |__
| .**|| ||| |**, | / / / /
=========||==============|/=///_/
�[32m :: Spring Boot :: �[39m �[2m (v1.4.0.RELEASE)�[0;39m

�[2m2016-09-04 21:36:55.285�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ main]�[0;39m �[36mhello.Application �[0;39m �[2m:�[0;39m Starting Application on farhan with PID 11810 (/home/farhan/Spring/Projects/gs-rest-hateoas-complete/target/classes started by farhan in /home/farhan/Spring/Projects/gs-rest-hateoas-complete)
�[2m2016-09-04 21:36:55.290�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ main]�[0;39m �[36mhello.Application �[0;39m �[2m:�[0;39m No active profile set, falling back to default profiles: default
�[2m2016-09-04 21:36:55.374�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ main]�[0;39m �[36ms.c.a.AnnotationConfigApplicationContext�[0;39m �[2m:�[0;39m Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5af3afd9: startup date [Sun Sep 04 21:36:55 WIB 2016]; root of context hierarchy
�[2m2016-09-04 21:36:56.866�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ main]�[0;39m �[36mo.s.j.e.a.AnnotationMBeanExporter �[0;39m �[2m:�[0;39m Registering beans for JMX exposure on startup
�[2m2016-09-04 21:36:56.884�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ main]�[0;39m �[36mhello.Application �[0;39m �[2m:�[0;39m Started Application in 2.067 seconds (JVM running for 2.561)
�[2m2016-09-04 21:36:56.885�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ Thread-1]�[0;39m �[36ms.c.a.AnnotationConfigApplicationContext�[0;39m �[2m:�[0;39m Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5af3afd9: startup date [Sun Sep 04 21:36:55 WIB 2016]; root of context hierarchy
�[2m2016-09-04 21:36:56.888�[0;39m �[32m INFO�[0;39m �[35m11810�[0;39m �[2m---�[0;39m �[2m[ Thread-1]�[0;39m �[36mo.s.j.e.a.AnnotationMBeanExporter �[0;39m �[2m:�[0;39m Unregistering JMX-exposed beans on shutdown
`

I'm really new to spring.. don't know how to solve the problem.

@aanfarhan if looks like you are running a different guide (it says gs-rest-hateoas in your logs). It also looks like you don't have a server running, probably because of something missing from the classpath, so the app just exits as soon as it starts.

@dsyer could you please tell what would be the reason in my case. link for my code https://github.com/ananthashankar/Rest-Services/tree/master/Greetings

$ git clone git@github.com:ananthashankar/Rest-Services.git
Cloning into 'Rest-Services'...
remote: Counting objects: 28, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 28 (delta 1), reused 25 (delta 0), pack-reused 0
...
$ cd Greetings/
$ mvn clean spring-boot:run
...
2016-09-04 14:17:18.980  INFO 78910 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-09-04 14:17:19.031  INFO 78910 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-09-04 14:17:19.035  INFO 78910 --- [           main] Greetings.Web_Services.App               : Started App in 1.941 seconds (JVM running for 8.009)
2016-09-04 14:17:27.703  INFO 78910 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'

Your repo launched on my machine.

Then, in another panel..

$ curl -v localhost:8080/greeting
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /greeting HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Sun, 04 Sep 2016 19:17:27 GMT
< 
* Connection #0 to host localhost left intact
{"id":1,"content":"Hello, World!"}
$ curl -v localhost:8080/greeting?name=Greg
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /greeting?name=Greg HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Sun, 04 Sep 2016 19:17:43 GMT
< 
* Connection #0 to host localhost left intact
{"id":2,"content":"Hello, Greg!"}

Looks good to me. Inside STS, did you right click the class with @SpringBootApplication annotation, and select "Run"?

@gregturn Thanks for the reply. Surprisingly it seems to be working now. All this time whenever I tried I was getting the above screenshot error. All I did was updating the project before running. I had updated the project several times before as well but it only worked this time. Neither it was working with Spring's starter guide code and I was running them as a SpringBoot app. Could you please tell what possible mistake I would've done in STS so that I won't repeat the same in future.

Refreshing and updating in STS will certainly help. It seems like there isn't actually a problem with the guide though.