В настоящее время у меня есть два RestTemplate
бина:
@Bean
@Primary
public RestTemplate jwtRestTemplate(
RestTemplateBuilder builder,
JWTService jwtService) {
return builder
.additionalInterceptors(
Collections.singletonList(
new JWTHeaderRequestInterceptor(jwtService)
)
)
.build();
}
@Bean
public RestTemplate rawRestTemplate(RestTemplateBuilder builder) {
return builder.build();
}
Первый является основным, а другой запрашивается @Qualifier("rawRestTemplate")
.
Однако яResTemplate
@RunWith(SpringRunner.class)
@SpringBootTest()
public class AuditoryTest {
@MockBean()
private RestTemplate frontOfficeRestTemplate;
@Autowired
private DocumentServiceBackOffice documentService;
DocumentServiceBackOffice
Конструктор:
public DocumentServiceBackOffice(RestTemplate restTemplate);
Я получаю исключение:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in net.gencat.transversal.espaidoc.backoffice.service.DocumentServiceBackOffice required a single bean, but 2 were found:
- rawRestTemplate: defined by method 'rawRestTemplate' in class path resource [net/gencat/transversal/espaidoc/backoffice/config/BackOfficeConfiguration.class]
- jwtRestTemplate: defined by method 'createMock' in null
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
Сообщениедовольно ясно, но я не совсем понимаю, как это решить.
Есть идеи?