我需要创建一个webservice客户端来获取sportsdata。
但是在尝试@Autowired sportsdata
时我遇到了异常。
例外:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [de.openligadb.schema.SportsdataSoap] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
JavaConfig :
@Configuration
@ComponentScan(basePackages = "com.example", excludeFilters = { @Filter(Configuration.class) })
public class MainConfig {
private @Value("${openligadb.wsdlDocumentUrl}") String wsdlDocumentUrl;
private @Value("${openligadb.endpointAddress}") String endpointAddress;
private @Value("${openligadb.namespaceUri}") String namespaceUri;
private @Value("${openligadb.serviceName}") String serviceName;
@Bean
public JaxWsPortProxyFactoryBean sportsdata() throws MalformedURLException {
JaxWsPortProxyFactoryBean ret = new JaxWsPortProxyFactoryBean();
ret.setWsdlDocumentUrl(new URL(wsdlDocumentUrl));
ret.setServiceInterface(SportsdataSoap.class);
ret.setEndpointAddress(endpointAddress);
ret.setNamespaceUri(namespaceUri);
ret.setServiceName(serviceName);
return ret;
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer ret = new PropertySourcesPlaceholderConfigurer();
ret.setLocation(new ClassPathResource("application.properties"));
return ret;
}
}
是的:我知道@PropertySource
但我需要创建一个bean,以便稍后在我的Controller中使用它。
答案 0 :(得分:4)
与FactoryBean
存在@Configuration
互操作性问题。有关详细信息,请查看at this answer。
简短版本是将bean明确添加到您的配置中。
@Bean
public SportsdataSoap sportsdataSoap() throws ... {
return (SportsdataSoap) sportsdata().getObject();
}