title: spring boot registering rest controller doesn't work without class level requestmapping
body: <p>boot application, however, even though my service component shows as registered bean in spring context its url is not getting registered. Basically, to register my component which has method level <code>@RequestMapping</code> annotation I need to define class level request mapping. And then it spring context is able to register the url handler.</p>
  <p>my directory structure looks like;</p>
  <pre><code>├── pom.xml
  ├── src
  │   ├── main
  │   │   ├── java
  │   │   │   └── com
  │   │   │       └── awesomecrypto
  │   │   │           └── backend
  │   │   │               ├── SpringBootApp.java
  │   │   │               ├── entity
  │   │   │               │   └── MarketData.java
  │   │   │               ├── repository
  │   │   │               │   └── MarketDataRepository.java
  │   │   │               └── service
  │   │   │                   └── MarketDataService.java
  │   │   └── resources
  </code></pre>
  <p><strong>SpringBootApp.java</strong></p>
  <pre><code>package com.awesomecrypto.backend;
  
  // import statements.
  
  @SpringBootApplication
  public class SpringBootApp {
  
      public static void main(String[] args) {
          ApplicationContext applicationContext = SpringApplication.run(SpringBootApp.class, args);
  
          for (String name: applicationContext.getBeanDefinitionNames()) {
              System.out.println(name);
          }
      }
  }
  </code></pre>
  <p><strong>MarketDataService</strong></p>
  <pre><code>package com.awesomecrypto.backend.service;
  
  // import statements here.
  
  @Component
  public class MarketDataService {
  
      @Autowired
      private MarketDataRepository marketDataRepository;
  
      @GetMapping(&quot;/marketData&quot;)
      @ResponseBody
      public String getMarketData() {
          return &quot;foobar&quot;;
      }
  }
  </code></pre>
  <p>Without having a <code>@RequestMapping</code> defined on <code>MarketDataService</code> class level there are no any url handlers registered for &quot;/marketData&quot; url.</p>
  <pre><code>2018-05-28 15:15:11.357  INFO 30618 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2018-05-28 15:15:11.357  INFO 30618 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1295 ms
  2018-05-28 15:15:11.460  INFO 30618 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
  2018-05-28 15:15:11.465  INFO 30618 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2018-05-28 15:15:11.465  INFO 30618 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2018-05-28 15:15:11.465  INFO 30618 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2018-05-28 15:15:11.465  INFO 30618 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2018-05-28 15:15:11.601  INFO 30618 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2018-05-28 15:15:11.813  INFO 30618 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c65519: startup date [Mon May 28 15:15:10 PDT 2018]; root of context hierarchy
  2018-05-28 15:15:11.915  INFO 30618 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error]}&quot; onto public org.springframework.http.ResponseEntity&lt;java.util.Map&lt;java.lang.String, java.lang.Object&gt;&gt; org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
  2018-05-28 15:15:11.916  INFO 30618 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/error],produces=[text/html]}&quot; onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
  2018-05-28 15:15:11.939  INFO 30618 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  2018-05-28 15:15:11.939  INFO 30618 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
  </code></pre>
  <p>On the other hand, <code>marketDataService</code> is registered in spring context which doesn't makes sense. Here is the related <code>getBeanDefinitionNames</code> logs.</p>
  <pre><code>org.springframework.context.event.internalEventListenerFactory
  springBootApp
  org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory
  marketDataRepository
  marketDataService
  org.springframework.boot.autoconfigure.AutoConfigurationPackages
  org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
  org.springframework.boot.autoconfigure.condition.BeanTypeRegistry
  </code></pre>
  <p>Now if I add <code>@RequestMapping(&quot;/test&quot;)</code> on top of <code>MarketDataService</code> then spring registers a url handler.</p>
  <pre><code>2018-05-28 15:20:31.320  INFO 31536 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quot;{[/test/marketData],methods=[GET]}&quot; onto public java.lang.String com.awesomecrypto.backend.service.MarketDataService.getMarketData()
  </code></pre>
  <p>I am running application with;</p>
  <blockquote>
  <p>mvn clean package</p>
  <p>mvn spring-boot:run</p>
  </blockquote>
  <p>All of the examples over the web doesn't mention about this and looks like it class level RequestMapping is not required but I couldn't make it. I appreciate for your help. Thanks!</p>