我试图将基于xml的bean配置转换为新应用程序的基于注释的配置。我陷入了在基于注释的方法中引用添加clientinterceptor bean的问题。
我尝试添加以下方法,但是不幸的是,它无法正常工作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
答案 0 :(得分:0)
您可能从NoSuchBeanDefinitionException
获得了applicationContext.getBean(securityInterceptor)
这意味着要么
的值 @Value("${bcus.ws.security.client.interceptor}")
private String securityInterceptor;
不能正确解析,或者您尚未定义此bean或尚未加载它。但是我不确定最后一点。
请发布ClientInterceptor
的bean定义,这样更容易帮助。
还请发布完整的异常,其外观应类似于:
...NoSuchBeanDefinitionException: No bean named '' available