title: How to replace an existing bean in spring boot application?
body: <p>I spring boot application, There already an bean creation in one auto configuraton class from a dependent jar like bellow:</p>
  
  <pre><code>@Bean
  @Order(100)
  public StaticRouteLocator staticRouteLocator(AdminServerProperties admin) {
      Collection&lt;ZuulRoute&gt; routes = Collections
              .singleton(new ZuulRoute(admin.getContextPath() + "/api/turbine/stream/**",
                      properties.getUrl().toString()));
      return new StaticRouteLocator(routes, server.getServletPrefix(), zuulProperties);
  }
  </code></pre>
  
  <p>Now I want to replace this bean, but I still need this jar which has this unwanted Bean creation. So I added another bean creation method in my main auto configuration class like this:</p>
  
  <pre><code>  @Bean(name="patchedStaticRouteLocator")
    @Order(10)
    @Primary
    @ConditionalOnMissingBean
    public StaticRouteLocator patchedStaticRouteLocator(AdminServerProperties admin) {
      Collection&lt;ZuulProperties.ZuulRoute&gt; routes = Collections
          .singleton(new ZuulProperties.ZuulRoute(admin.getContextPath(),
              properties.getUrl().toString()));
      return new StaticRouteLocator(routes, server.getServletPrefix(), zuulProperties);
    }
  </code></pre>
  
  <p>But this failed to replace the target bean. The error msg is clear and easy to understand:</p>
  
  <pre><code>org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.cloud.netflix.zuul.filters.RouteLocator] is defined: more than one 'primary' bean found among candidates: [routeLocator, patchedStaticRouteLocator, staticRouteLocator, compositeRouteLocator, applicationRouteLocator]
  </code></pre>
  
  <p>My question what is the right way to replace such existing bean in spring boot? Thanks in advance.</p>