2015-06-18 2 views
0

Использование весеннего ботинка, как Autowire applicationContext?Как Autowire собственность перед другим?

Он должен быть autowired перед вызовом endpoint()

@Configuration 
@EnableTransactionManagement 
@EnableAutoConfiguration 
@ComponentScan({"com.dev.core.services", "com.dev.core.wservices"}) 
@ImportResource({ "classpath:META-INF/cxf/cxf.xml" }) 
public class ContextConfig extends SpringBootServletInitializer { 
    @Autowired 
    private static ApplicationContext applicationContext; 
    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(ContextConfig.class); 
    } 
    @Bean 
    public EndpointImpl endpoint() { 
    // applicationContext is null how to fix that ? 
     EndpointImpl endpoint = 
      new EndpointImpl(cxfBus, applicationContext.getBean(IWCustomerService.class)); 
     endpoint.publish("/CustomerService"); 
     return endpoint; 
    } 
} 

ответ

2

static полей игнорируются Spring.

Если вы не используете какой-либо метод main, настройте приложение, вам не нужно будет напрямую использовать ApplicationContext.

Здесь вы хотите использовать его для извлечения бобов типа IWCustomerService. Вместо этого пусть Spring приложит его для вас.

@Bean 
public EndpointImpl endpoint(IWCustomerService customerService) { 
    EndpointImpl endpoint = 
     new EndpointImpl(cxfBus, customerService); 
    endpoint.publish("/CustomerService"); 
    return endpoint; 
} 
Смежные вопросы