Мне не удалось передать бин клиентскому перехватчику - PullRequest
0 голосов
/ 13 июня 2019

Я пытался преобразовать конфигурацию bean-компонента на основе xml в конфигурацию на основе аннотаций для нового приложения.Я застрял при добавлении bean-компонента clientinterceptor в подходе, основанном на аннотациях.

Я попытался добавить приведенный ниже подход, к сожалению, он не работает, tomcat терпит неудачу, и в моем коде перехватчика происходит сбой:

@Configuration
@PropertySource({"classpath:/envs/${env}/vendors-service.properties"})
public class WebServiceClientConfig {

    @Autowired
    ApplicationContext applicationContext;
    @Value("${bcus.ws.security.client.interceptor}")
    private String securityInterceptor;
    @Bean(name = "deviceService")
    public DeviceServiceImpl deviceService(Jaxb2Marshaller marshaller) {
        DeviceServiceImpl deviceService = new DeviceServiceImpl();
        List<ClientInterceptor> interceptors = new ArrayList<>();
        interceptors.add((ClientInterceptor) applicationContext.getBean(securityInterceptor));
        deviceService.setInterceptors((ClientInterceptor[]) interceptors.toArray());
        return deviceService;
    }
    <bean id="deviceService" class="com.barclaycardus.svc.common.proxy.device.DeviceServiceImpl" parent="baseJaxbService">
          <constructor-arg ref="messageFactory" />
           <property name="defaultUri" value="${device.service.url}" />
            <property name="interceptors">
                <list>
                    <ref bean="${bcus.ws.security.client.interceptor}" />
                </list>
            </property>
     </bean>
 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deviceService' defined in class path resource [com/barclaycardus/svc/vendorgateway/core/config/WebServiceClientConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.barclaycardus.svc.vendorgateway.core.deviceservice.DeviceServiceImpl]: Factory method 'deviceService' threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named

1 Ответ

0 голосов
/ 13 июня 2019

вы, вероятно, получаете NoSuchBeanDefinitionException из applicationContext.getBean(securityInterceptor)

Это означает, что либо значение

    @Value("${bcus.ws.security.client.interceptor}")
    private String securityInterceptor;

не разрешено правильно, либо вы не определили этот компонент или егоеще не загружен.Но я не уверен насчет последнего пункта.

Пожалуйста, опубликуйте свое определение бина для ClientInterceptor, тогда вам будет проще помочь.

Также, пожалуйста, опубликуйте полное исключение, которое должно выглядеть следующим образом:

...NoSuchBeanDefinitionException: No bean named '' available

С наилучшими пожеланиями, WiPu

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...