title: Spring Boot: Cannot access REST Controller on localhost (404)
body: <p>I am trying to adapt the REST Controller example on the Spring Boot website.
  Unfortunately I've got the following error when I am trying to access the <code>localhost:8080/item</code> URL. </p>
  
  <pre><code>{
    "timestamp": 1436442596410,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/item"
  }
  </code></pre>
  
  <p>POM:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
     &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
     &lt;groupId&gt;SpringBootTest&lt;/groupId&gt;
     &lt;artifactId&gt;SpringBootTest&lt;/artifactId&gt;
     &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
     &lt;properties&gt;
        &lt;javaVersion&gt;1.8&lt;/javaVersion&gt;
        &lt;mainClassPackage&gt;com.nice.application&lt;/mainClassPackage&gt;
        &lt;mainClass&gt;${mainClassPackage}.InventoryApp&lt;/mainClass&gt;
     &lt;/properties&gt;
  
     &lt;build&gt;
        &lt;plugins&gt;
           &lt;plugin&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.3&lt;/version&gt;
              &lt;configuration&gt;
                 &lt;source&gt;${javaVersion}&lt;/source&gt;
                 &lt;target&gt;${javaVersion}&lt;/target&gt;
              &lt;/configuration&gt;
           &lt;/plugin&gt;
  
           &lt;!-- Makes the Spring Boot app executable for a jar file. The additional configuration is needed for the cmd: mvn spring-boot:repackage 
              OR mvn spring-boot:run --&gt;
           &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  
              &lt;configuration&gt;
                 &lt;mainClass&gt;${mainClass}&lt;/mainClass&gt;
                 &lt;layout&gt;ZIP&lt;/layout&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                 &lt;execution&gt;
                    &lt;goals&gt;
                       &lt;goal&gt;repackage&lt;/goal&gt;
                    &lt;/goals&gt;
                 &lt;/execution&gt;
              &lt;/executions&gt;
           &lt;/plugin&gt;
  
           &lt;!-- Create a jar with a manifest --&gt;
           &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.4&lt;/version&gt;
              &lt;configuration&gt;
                 &lt;archive&gt;
                    &lt;manifest&gt;
                       &lt;mainClass&gt;${mainClass}&lt;/mainClass&gt;
                    &lt;/manifest&gt;
                 &lt;/archive&gt;
              &lt;/configuration&gt;
           &lt;/plugin&gt;
        &lt;/plugins&gt;
     &lt;/build&gt;
  
     &lt;dependencyManagement&gt;
        &lt;dependencies&gt;
           &lt;dependency&gt;
              &lt;!-- Import dependency management from Spring Boot. This replaces the usage of the Spring Boot parent POM file. --&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-dependencies&lt;/artifactId&gt;
              &lt;version&gt;1.2.5.RELEASE&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
           &lt;/dependency&gt;
  
           &lt;!-- more comfortable usage of several features when developing in an IDE. Developer tools are automatically disabled when 
              running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, 
              then it is considered a 'production application'. Applications that use spring-boot-devtools will automatically restart whenever files 
              on the classpath change. --&gt;
           &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
           &lt;/dependency&gt;
        &lt;/dependencies&gt;
     &lt;/dependencyManagement&gt;
  
     &lt;dependencies&gt;
        &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;
  
        &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
           &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
  
        &lt;dependency&gt;
           &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
           &lt;artifactId&gt;guava&lt;/artifactId&gt;
           &lt;version&gt;15.0&lt;/version&gt;
        &lt;/dependency&gt;
     &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Starter-Application:</p>
  
  <pre><code>package com.nice.application;
  @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
  public class InventoryApp {
     public static void main( String[] args ) {
        SpringApplication.run( InventoryApp.class, args );
     }
  }
  </code></pre>
  
  <p>REST-Controller:</p>
  
  <pre><code>package com.nice.controller; 
  @RestController // shorthand for @Controller and @ResponseBody rolled together
  public class ItemInventoryController {
     public ItemInventoryController() {
     }
  
     @RequestMapping( "/item" )
     public String getStockItem() {
        return "It's working...!";
     }
  
  }
  </code></pre>
  
  <p>I am building this project with Maven.
  Started it as jar (spring-boot:run) and as well inside the IDE (Eclipse).</p>
  
  <p>Console Log:</p>
  
  <pre><code>2015-07-09 14:21:52.132  INFO 1204 --- [           main] c.b.i.p.s.e.i.a.InventoryApp          : Starting InventoryApp on 101010002016M with PID 1204 (C:\eclipse_workspace\SpringBootTest\target\classes started by MFE in C:\eclipse_workspace\SpringBootTest)
  2015-07-09 14:21:52.165  INFO 1204 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7a3d45bd: startup date [Thu Jul 09 14:21:52 CEST 2015]; root of context hierarchy
  2015-07-09 14:21:52.661  INFO 1204 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
  2015-07-09 14:21:53.430  INFO 1204 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  2015-07-09 14:21:53.624  INFO 1204 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
  2015-07-09 14:21:53.625  INFO 1204 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.23
  2015-07-09 14:21:53.731  INFO 1204 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2015-07-09 14:21:53.731  INFO 1204 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1569 ms
  2015-07-09 14:21:54.281  INFO 1204 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
  2015-07-09 14:21:54.285  INFO 1204 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
  2015-07-09 14:21:54.285  INFO 1204 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2015-07-09 14:21:54.508  INFO 1204 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7a3d45bd: startup date [Thu Jul 09 14:21:52 CEST 2015]; root of context hierarchy
  2015-07-09 14:21:54.573  INFO 1204 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  2015-07-09 14:21:54.573  INFO 1204 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
  2015-07-09 14:21:54.594  INFO 1204 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2015-07-09 14:21:54.594  INFO 1204 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2015-07-09 14:21:54.633  INFO 1204 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2015-07-09 14:21:54.710  INFO 1204 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
  2015-07-09 14:21:54.793  INFO 1204 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
  2015-07-09 14:21:54.795  INFO 1204 --- [           main] c.b.i.p.s.e.i.a.InventoryApp          : Started InventoryApp in 2.885 seconds (JVM running for 3.227)
  2015-07-09 14:22:10.911  INFO 1204 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
  2015-07-09 14:22:10.911  INFO 1204 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
  2015-07-09 14:22:10.926  INFO 1204 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 15 ms
  </code></pre>
  
  <p>What I've tried so far: </p>
  
  <ul>
  <li>Accessing the URL with the application name (InventoryApp)</li>
  <li>Put another <code>@RequestMapping("/")</code> at class level of the <code>ItemInventoryController</code></li>
  </ul>
  
  <p>As far as I understood, I won't need an application-context when using Spring Boot. Am I right?</p>
  
  <p>What else can I do to access the method via URL?</p>