0

I am new to spring-boot and have created a dummy app which has one controller method.

The packaging type for the application is mentioned as jar in pom file. On deployment there are no errors in logs.

But still after a successful build and deployment when i try to access my localhost from browser i get a 404 error.

Below are the things which i have already tried to resolve the issue :

1) Including my main class and controller class in same package. 2) Having my main class in root package and controller in sub package. 3) Defining @RestController on class as well as method. 4) Extending SpringBootServletInitializer in my main class

package com.test.controller;

    @SpringBootApplication
    public class TestApplication  {

        public static void main(String[] args) {

            SpringApplication.run(TestApplication.class, args);
        }

    }


 **Controller class**




     package com.test.controller;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import org.springframework.stereotype.Controller;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestMethod;

        @RestController
        public class TestController {

            public final Logger logger = LoggerFactory.getLogger(TestController.class);

            @RequestMapping(value = "/test", method = RequestMethod.GET)
            public String test() {
                logger.info("This is a test message to check if logback is working");
                return "Hello World";
            }
        }

So as per the result i should have got a Hello World message on my web page but instead i got an 404 error.

Below is the log on service startup :

    "C:\Program Files\Java\jdk1.8.0_161\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Repositories\Personal\Mindship\resume-parser "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3\plugins\maven\lib\maven3\bin\m2.conf" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.3\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version2019.1.3 spring-boot:run
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building resume-parser 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) > test-compile @ resume-parser >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ resume-parser ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ resume-parser ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ resume-parser ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Repositories\Personal\Mindship\resume-parser\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ resume-parser ---
[INFO] No sources to compile
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) < test-compile @ resume-parser <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) @ resume-parser ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.6.RELEASE)

2019-07-19 14:21:43.166  INFO 7384 --- [           main] c.r.controller.ResumeParserApplication   : Starting ResumeParserApplication on WKSBAN09VDF8243 with PID 7384 (C:\Repositories\Personal\Mindship\resume-parser\target\classes started by ankit.srivastava in C:\Repositories\Personal\Mindship\resume-parser)
2019-07-19 14:21:43.187  INFO 7384 --- [           main] c.r.controller.ResumeParserApplication   : No active profile set, falling back to default profiles: default
2019-07-19 14:21:47.574  INFO 7384 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-07-19 14:21:47.685  INFO 7384 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-07-19 14:21:47.689  INFO 7384 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-07-19 14:21:47.956  INFO 7384 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-07-19 14:21:47.956  INFO 7384 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4599 ms
2019-07-19 14:21:48.900  INFO 7384 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-07-19 14:21:49.338  INFO 7384 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-07-19 14:21:49.338  INFO 7384 --- [           main] c.r.controller.ResumeParserApplication   : Started ResumeParserApplication in 7.906 seconds (JVM running for 17.28)
2019-07-19 14:22:55.499  INFO 7384 --- [nio-8080-exec-8] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-07-19 14:22:55.500  INFO 7384 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-07-19 14:22:55.528  INFO 7384 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Completed initialization in 20 ms
ANKIT SRIVASTAVA
  • 133
  • 4
  • 14

0 Answers0