r/SpringBoot • u/Dependent_Increase34 • Jul 14 '26
Question Kinda stumped
I'm currently learning spring and I wanna test one of my class
this is the configuration
@Configuration
public class EmbeddingClientConfig {
...constructor
@Bean
IEmbeddingClient embeddingClient(RestClient.Builder builder, MeterRegistry registry){
return new EmbeddingClient(
builder.baseUrl(apiUrl).build(),
registry
);
};
}
this is the test class
@RestTestClient(EmbeddingClientConfig.class)
public class EmbeddingClientTests {
@Autowired
private MockRestServiceServer server;
@Autowired
private IEmbeddingClient client;
@Autowired
private MeterRegistry registry;
...rest of class
and for some reason it gives me this error:
java.lang.IllegalStateException: Unable to use auto-configured MockRestServiceServer since a mock server customizer has not been bound to a RestTemplate or RestClientjava.lang.IllegalStateException: Unable to use auto-configured MockRestServiceServer since a mock server customizer has not been bound to a RestTemplate or RestClient
I don't understand why my config is able to be injected but not MockRestService?
any help / readings / direction would be appreciated.
thank you
1
Upvotes
View all comments
Show parent comment
1
u/BanaTibor Jul 15 '26
Probably MockRestServiceServer needs a customizer which either creates a RestTemplate or RestClient for it.
The problem described on the link is that they have multiple RestTemplate or RestClient beans in the context, and your problem is that you have none.