出现问题时我这样使用依赖注入

@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; 
    } 
} 

加入前置操作

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!