Autowire service to use inside bean

Of course you can do it. Try it like this:

public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, 
                      @Autowired AccountDiscoveryService discoveryService) {
    //Objects.requiredNotNull(discoveryService); //null check if discoveryService can be null
    return builder.routes()
                  .route(r -> r.path("/api/wallet/slot/thunderkick/**") //intercept calls 
                               .uri(discoveryService.getHost()) //forward to

Also you can move String values to property file. It is better way for configuration classes.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top