You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to provide my own implementation of a @FeignClient annotated interface based on a configuration setting? I'd like to be able to define a "local" Spring profile, for example, that will use a mocked out interface that will not try to connect to any external endpoints, allowing me to run my Spring boot application without any external dependencies being up. Additional profiles would allow the clients to be instantiated and injected as they currently are.
I have tried using the @ConditionalOnProperty annotation to serve up a bean for the interface as follows, but that doesn't work:
@FeignClient(name = "http://foo-service")
public interface FooResource {
@RequestMapping(value = "/doSomething", method = GET)
String getResponse();
}
...
@Configuration
public class AppConfig {
@Bean
@ConditionalOnProperty(prefix = "spring.profile", name = "active", havingValue="local")
public FooResource fooResource() {
return new FooResource() {
@Override
public String getResponse() {
return "testing";
}
};
}
}
When the application launches the bean is ignored, and my FooResource instance still tries to contact the remote service.
How can I achieve my aim?
The text was updated successfully, but these errors were encountered:
This might be something Spring Cloud Contract can help with. Although generally the contracts are only used in tests as far as I know. @marcingrzejszczak thoughts?
Is it possible to provide my own implementation of a
@FeignClient
annotated interface based on a configuration setting? I'd like to be able to define a "local" Spring profile, for example, that will use a mocked out interface that will not try to connect to any external endpoints, allowing me to run my Spring boot application without any external dependencies being up. Additional profiles would allow the clients to be instantiated and injected as they currently are.I have tried using the
@ConditionalOnProperty
annotation to serve up a bean for the interface as follows, but that doesn't work:When the application launches the bean is ignored, and my
FooResource
instance still tries to contact the remote service.How can I achieve my aim?
The text was updated successfully, but these errors were encountered: