Spring adds request mappings for beans that aren't annotated with @Controller

37 views Asked by At

I have a library that contains the DTO and service interface.

@RequestMappping("/api/foo")
public interface FooApi {

   @GetMapping("/{id}")
   Foo getFooById(@pathVariable long id);

}

The server implements that interface:

@RestController
public FooController implements FooApi {

    Foo getFooById(long id) {
         return fooService.getById(id);
    }

}

And I have clients that also implement that interface:

@Component
public FooClient implements FooApi {

    Foo getFooById(long id) {
         return restTemplate.getObject(baseUrl + "/api/foo/{id}", ...);
    }

}

(in the future the client implementation will get derived from the annotations at runtime: clientFactory.createInstance(FooApi.class))

Is there a way to tell Spring to not treat the FooClient as a Controller, because I didn't annotate it as such? (Without removing the @RequestMappings from the FooApi interface entirely?)

I'm using Spring-Boot 2.7.

0

There are 0 answers