Получение неудовлетворенного исключения зависимости. Ошибка создания bean-компонента с именем при переходе с Spring на SJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Получение неудовлетворенного исключения зависимости. Ошибка создания bean-компонента с именем при переходе с Spring на S

Сообщение Anonymous »

Здравствуйте, я столкнулся с проблемой в моем приложении Spring. Я перехожу с Spring 2.x. до Spring 3.x. и вижу несколько проблем.:

Код: Выделить всё

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'taxCalculator': Unsatisfied dependency expressed through field 'taxService': Error creating bean with name 'vertexService': Unsatisfied dependency expressed through field 'taxServiceInterpreter': Error creating bean with name 'taxServiceInterpreter': Injection of resource dependencies failed
Я просматриваю дорожку стека, и она сужается до этого компонента, который не создается должным образом.

Код: Выделить всё

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'taxService' available
Вот как я это настроил:

Код: Выделить всё

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
public class TaxServiceInterpreter {

@Autowired
LoggerUtils loggerUtils;

@Resource(name = "taxService")
RestClient restClient;
а затем в классе конфигурации у меня есть это

Код: Выделить всё

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;

import org.apache.hc.core5.util.TimeValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClient;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@Slf4j
@Configuration
@JsonPropertyOrder
public class BoilerPlateConfig {
@Bean("taxService")
public RestClient retrieveTemplateForTaxService() {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(taxServiceRestCallSocketTimeout, TimeUnit.MILLISECONDS)
.setResponseTimeout(taxServiceRestCallReadTimeout, TimeUnit.MILLISECONDS).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(poolingConnectionManager()).setDefaultRequestConfig(requestConfig).build();
HttpComponentsClientHttpRequestFactory factory =  new HttpComponentsClientHttpRequestFactory(httpClient);
return RestClient.builder().requestInterceptor(new RequestResponseLoggingInterceptor()).requestFactory(factory).build();
}
Эта настройка будет работать в более старой версии Spring, в которой раньше она у меня была и использовалась в качестве resttemplate, а не restclient..

Код: Выделить всё

    public RestTemplate retrievetemplateForTaxService() {
RestTemplate restTemplate = new RestTemplateBuilder().requestFactory(this::clientHttpRequestFactoryTaxService)
.build();
restTemplate.setInterceptors(Collections.singletonList(new RequestResponseLoggingInterceptor()));
return restTemplate;
}

Код: Выделить всё

@Component
public class TaxServiceInterpreter {

@Autowired
LoggerUtils loggerUtils;

@Autowired
RestTemplate restTemplate;
Может ли кто-нибудь указать мне правильное направление, почему он не может найти его с помощью этого тега ресурса?

Подробнее здесь: https://stackoverflow.com/questions/793 ... when-migra
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»