title: Programatically define RequestMappings for a custom Spring Boot starter
body: <p>I'm trying to create a Spring Boot starter project that defines controllers programmatically based on the existence of certain types of beans. In the auto configuration class I defined a <code>RequestMappingHandlerMapping</code> where I register the handlers programmatically similar to the following:</p>
  <pre><code>@Bean
  public RequestMappingHandlerMapping customRoutes(ApplicationContext context) {
      var handlerMapping = new RequestMappingHandlerMapping();
      findTargetBeans(context).forEach((name, bean) -&gt;
          var getMapping = RequestMappingInfo
                      .paths(&quot;/&quot; + name)
                      .methods(RequestMethod.GET)
                      .produces(MediaType.APPLICATION_JSON_VALUE)
                      .build();
          handlerMapping.registerMapping(getMapping, createHandler(), getHanderMethod());
      );
      return handlerMapping;
  }
  </code></pre>
  <p>This seems to build just fine, but when I try hitting the registered paths, I get a 404 response. Am I missing something? Do I need additional configuration to make this programmatic routing to work? I've been looking at old questions <a href="https://stackoverflow.com/q/5758504/404604">like this one</a>, and <a href="https://stackoverflow.com/q/30402453/404604">this one</a>, but none of the answers work for me.</p>