Я кодировал эти два компонента:
@Bean
public HttpClient httpClient() throws Exception {
LOG.debug("http client for NO PRE");
return HttpClients.custom().build();
}
@Bean
@Profile("pre")
public HttpClient httpClientPre() throws Exception {
LOG.debug("http client for PRE");
//...
HttpClient client = HttpClients.custom().build();
return client;
}
С другой стороны, у меня есть еще один компонент:
@Bean
@Primary
public RestTemplate restTemplate(RestTemplateBuilder builder, HttpClient httpClient) throws Exception {
return builder.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(httpClient))
.build();
}
Как вы можете понять, когда "pre"
активен, я хочу httpClientPre
достигнут. Однако, несмотря на то, что активный профиль «pre», он не достигнут. Смотрите журналы:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)
13:20:31.746 [main] INFO n.g.t.e.s.SchedulerApplication - Starting SchedulerApplication on psgd with PID 9538 (/home/jeusdi/projects/repositori-digital/rep-digital-scheduler/target/classes started by jeusdi in /home/jeusdi/projects/repositori-digital)
13:20:31.760 [main] DEBUG n.g.t.e.s.SchedulerApplication - Running with Spring Boot v2.0.4.RELEASE, Spring v5.0.8.RELEASE
13:20:31.767 [main] INFO n.g.t.e.s.SchedulerApplication - The following profiles are active: pre <<<<<<<<<<<<
Однако я ожидал получить журнал для "http client for PRE"
. Тем не менее, я получаю:
13:20:48.613 [main] DEBUG n.g.t.e.s.c.ServicesConfiguration - http client for NO PRE <<<<<<
Это означает, что httpClientPre
не достигается, несмотря на текущий профиль pre
.
Есть идеи?
РЕДАКТИРОВАТЬ
Я также пытался с @Profile("!pre")
, но я получаю это сообщение:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method restTemplate in net.gencat.transversal.espaidoc.scheduler.config.ServicesConfiguration required a bean named 'httpClient' that could not be found.
Action:
Consider defining a bean named 'httpClient' in your configuration.
EDIT2
Я также пытался с:

Но он продолжает получать сообщение выше.