1

I'm trying to follow this tutorial, http://spring.io/guides/gs/rest-service/ to create a simple Spring REST implementation, and have got to the end of the project. When I open up my application on localhost:8080/greeting, I get a 404 not found error. I have been searching for a long time with no result on how to solve this. I'm not sure if I need a web.xml, as the tutorial states, with Jackson, a web.xml isn't needed.

It states "And because the application also depends on Spring MVC (spring-webmvc.jar), a Spring MVC DispatcherServlet is configured and registered for you — no web.xml necessary'

So, I'm not entirely sure what I'm doing wrong here. I am using Spring Tool Suite, and have also tried to import the Spring REST tutorial in case that makes any difference. Should this be created as a Spring MVC project in Spring Tool Suite?

Any help is much appreciated!

This is what my project currently looks like: enter image description here

AkshaiShah
  • 5,739
  • 11
  • 37
  • 45
  • see the sample code at https://github.com/fmucar/spring-rest-sample if that makes sense – fmucar Nov 26 '13 at 22:57
  • @fmucar I'm just trying to understand whether I need a web.xml file or not, as the tutorial says you don't need one, but in the sample project you showed me, there is one there. – AkshaiShah Nov 26 '13 at 23:00
  • Deployment descriptor (web.xml) is indeed **optional** if annotations are used. So it's definitely NOT the reason (again **if** you followed the tutorial exactly). – informatik01 Nov 26 '13 at 23:14
  • why do you have a WebContent folder in your project? are you running the Application.java to start your server or are you trying to deploy onto a webcontainer in eclipse? – gadget Nov 26 '13 at 23:16
  • @gadget I am deploying the whole project to a Apache server in Spring tool suite, by right click on project -> run on server. The WebContent folder is there from when I created a new Spring MVC project. Is that not the right thing to do? – AkshaiShah Nov 26 '13 at 23:18
  • @informatik01 I think the issue has occurred because the tutorial did not state what type of project to create, i.e. a spring project, spring mvc project etc, that's where i'm getting confused. – AkshaiShah Nov 26 '13 at 23:20
  • @AkshaiShah Quote from the tutorial (emphasis mine): "You package everything in a single, executable JAR file, driven by a good old Java main() method. Along the way, you use Spring’s support for embedding the Tomcat servlet container as the HTTP runtime, **instead of deploying to an external instance**." See the following section again: [Run the service](http://spring.io/guides/gs/rest-service/#_run_the_service) – informatik01 Nov 26 '13 at 23:21
  • In the mentioned tutorial they don't need a web.xml because they are using Spring Boot to bootstrap the application. In case of webcontainer deployments you will need a web.xml at least to configure your DispatcherServlet. – gadget Nov 26 '13 at 23:24
  • @informatik01 From that quote, I understand that I am deploying it correctly, through the tomcat instance in STS. – AkshaiShah Nov 26 '13 at 23:24
  • @gadget Ok that's fine. I am not using a web container deployment at the moment. I am just trying to run it internally, but still doesn't seem to be working. – AkshaiShah Nov 26 '13 at 23:26
  • by internally you mean you are running the main method of your Application class, right? – gadget Nov 26 '13 at 23:28
  • @AkshaiShah The tutorial clearly states that doing the way it's described it must be run as an ordinary **executable JAR**: `java -jar target/gs-rest-service-0.1.0.jar` – informatik01 Nov 26 '13 at 23:29
  • ah I didn't realise it had to be run as a spring boot app. Ok I managed to get it working, but is there no way I could convert it to a dynamic web project, so I could run it through a apache server by run as -> run on server? – AkshaiShah Nov 26 '13 at 23:32
  • 1
    @AkshaiShah See this: [Converting a Spring Boot JAR Application to a WAR](http://spring.io/guides/gs/convert-jar-to-war/) – informatik01 Nov 26 '13 at 23:34

0 Answers0