나는 sportsdata를 얻기 위해 webservice 클라이언트를 생성해야합니다. 그러나 @Autowired sportsdata
을 시도 할 때 예외가 발생합니다.스프링 JavaConfig + JAX-WS 클라이언트
예외 :
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
알고 있지만 나중에 그것을 사용하는 나는 빈을 만들 필요가 내 컨트롤러도.
그 전에 'afterPropertiesSet()'을 호출하는 것을 잊지 마십시오. –
아니면 SportsdataSoap을 직접 반환하는 메서드를 수정할 수 있습니다 ('return (SportsdataSoap) ret.getObject()') ?! – dtrunk
아니요, Spring은 FactoryBean을 초기화해야합니다. FactoryBean은 * @Bean으로 완료됩니다. 그 전에 직접 getObject()를 호출하면 AFAIK가 null이됩니다. –