出現問題時我這樣使用依賴注入
@Configuration
public class WebServiceConfig {
@Autowired
private IMessageWebService messageWebService;
@Bean
public Endpoint endpointHttp() {
EndpointImpl endpoint = new EndpointImpl(springBus(), messageWebService);
endpoint.publish("/messageWebService");
return endpoint;
}
}
出錯信息
Caused by: java.lang.NullPointerException: null
方法一
下面這樣處理可以解決問題
@Configuration
public class WebServiceConfig {
@Bean
public Endpoint endpointHttp(IMessageWebService messageWebService) {
EndpointImpl endpoint = new EndpointImpl(springBus(), messageWebService);
endpoint.publish("/messageWebService");
return endpoint;
}
}
我們不使用自動注入,問題解決
方法二
@Configuration
@DependsOn(value = "springUtil")
public class WebServiceConfig {
@Autowired
private IMessageWebService messageWebService;
@Bean
public Endpoint endpointHttp() {
EndpointImpl endpoint = new EndpointImpl(springBus(), messageWebService);
endpoint.publish("/messageWebService");
return endpoint;
}
}