Spring JavaConfig + JAX-WS Client

时间:2013-07-24 20:11:11

标签: spring jax-ws

我需要创建一个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中使用它。

1 个答案:

答案 0 :(得分:4)

FactoryBean存在@Configuration互操作性问题。有关详细信息,请查看at this answer

简短版本是将bean明确添加到您的配置中。

@Bean
public SportsdataSoap sportsdataSoap() throws ... {

    return (SportsdataSoap) sportsdata().getObject();
}