0

I am trying to create my first rest API using this simple tutorial https://spring.io/guides/gs/rest-service/ and cannot seem to find it online. First off, it installs through mvn clean install successfully and then when I run on server with tomcat it opens browser to http://localhost:8080/rest-service/ but returns Status 404. I have tried messing with the URL to give different end points but it is unsuccessful. I cloned from "git clone https://github.com/spring-guides/gs-rest-service.git"

Tried:
http://localhost:8080/rest-service/greeting
http://localhost:8080/rest-service/greeting?name=test
http://localhost:8080/greeting?name=test
http://localhost:8080/gs-rest-service/greeting
http://localhost:8080/gs-rest-service/greeting?name=test

The tutorial states: "When you finish, you can check your results against the code in gs-rest-service/complete" my project does not contain a complete folder.
The pom.xml:

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>rest-service</artifactId> <version>0.0.1-SNAPSHOT</version> <name>rest-service</name> <description>Demo project for Spring Boot</description> <properties> 

The tomcat server is online and running because other applications are hosted on it and I can successfully find them on a browser. However, the server.xml file states port # is 8089 meanwhile I navigate to http://localhost:8080/project_name to find other projects.

Greating controller exists as so:

@RestController public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); @GetMapping("/greeting") public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); } } 

UPDATE WITH LOG

Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server version name: Apache Tomcat/9.0.43 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server built: Jan 28 2021 20:25:45 UTC Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server version number: 9.0.43.0 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: OS Name: Windows 10 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: OS Version: 10.0 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Architecture: amd64 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Java Home: C:\Users\AHorner\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_15.0.2.v20210201-0955\jre Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Version: 15.0.2+7-27 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Vendor: Oracle Corporation Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: CATALINA_BASE: C:\Users\AHorner\eclipse-workspace\eclipse-workspace-ee\.metadata\.plugins\org.eclipse.wst.server.core\tmp1 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: CATALINA_HOME: C:\apache-tomcat-9.0.43 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dcatalina.base=C:\Users\AHorner\eclipse-workspace\eclipse-workspace-ee\.metadata\.plugins\org.eclipse.wst.server.core\tmp1 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dcatalina.home=C:\apache-tomcat-9.0.43 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dwtp.deploy=C:\Users\AHorner\eclipse-workspace\eclipse-workspace-ee\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dfile.encoding=Cp1252 Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages Mar 03, 2021 4:20:44 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: Loaded Apache Tomcat Native library [1.2.26] using APR version [1.7.0]. Mar 03, 2021 4:20:44 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. Mar 03, 2021 4:20:44 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] Mar 03, 2021 4:20:44 PM org.apache.catalina.core.AprLifecycleListener initializeSSL INFO: OpenSSL successfully initialized [OpenSSL 1.1.1i 8 Dec 2020] Mar 03, 2021 4:20:44 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-nio-8080"] Mar 03, 2021 4:20:44 PM org.apache.catalina.startup.Catalina load INFO: Server initialization in [1057] milliseconds Mar 03, 2021 4:20:44 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service [Catalina] Mar 03, 2021 4:20:44 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet engine: [Apache Tomcat/9.0.43] Mar 03, 2021 4:20:45 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:45 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:47 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:47 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:48 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:48 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Mar 03, 2021 4:20:48 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-nio-8080"] Mar 03, 2021 4:20:48 PM org.apache.catalina.startup.Catalina start INFO: Server startup in [3576] milliseconds 
3
  • How do you start your server/project? Do you launch it from an IDE or from a console? Can you show us some log? Commented Mar 3, 2021 at 19:44
  • Share your log. Commented Mar 3, 2021 at 21:04
  • @Mannekenpix I run it from Eclipse. Right click, run on server. I added the log od the server startup Commented Mar 3, 2021 at 21:22

1 Answer 1

0

You start a Tomcat and not the main Spring Boot class. You should run this class: https://github.com/spring-guides/gs-rest-service/blob/master/complete/src/main/java/com/example/restservice/RestServiceApplication.java

It is the main Spring Boot class and it will start the embedded Tomcat.

In the guide it is specified:

The main() method uses Spring Boot’s SpringApplication.run() method to launch an application.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.