【发布时间】:2015-06-18 01:04:57
【问题描述】:
使用spring boot,如何自动装配applicationContext?
必须在调用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;
}
}
【问题讨论】:
标签: spring spring-boot