【发布时间】:2013-07-24 20:11:10
【问题描述】:
我需要创建一个 Web 服务客户端来获取 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 中使用它。
【问题讨论】: