【发布时间】:2017-03-29 11:21:08
【问题描述】:
我正在开发一个 Spring Boot 应用程序,我正在使用该应用程序来公开一个 SOAP Web 服务。我在 Spring Boot 应用程序中使用 Apache CFX 框架进行 SOAP impl。我正在使用基于注释的方法。
我在从其中一个 Bean 中的 Spring Boot 配置文件中设置应用程序上下文时遇到问题。下面是我的代码。
@SpringBootApplication
@ComponentScan("com.test")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
配置文件如下。
@Configuration
public class WebServiceConfiguration {
//All individual bean definitions should go here
@Autowired
ApplicationContext appContext;
@Bean
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean(name="IValidator")
public IValidator getValidator(){
return new Validator();
}
@Bean(name="SOAPprocessImpl")
public IPSoap getService() {
return new SOAPprocessImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), getService());
endpoint.publish("/WS_1.0");
endpoint.setWsdlLocation("process.wsdl");
return endpoint;
}
现在我有了 bean SOAPprocessImpl 实现,我需要在其中获取应用程序上下文,以便获得 Validator bean 的句柄。我已在配置文件中将 SOAPprocessImpl 声明为 bean。代码如下
@javax.jws.WebService (endpointInterface="com.test.IPSoap")
public class SOAPprocessImpl implements IPSoap, ApplicationContextAware {
private static ApplicationContext context;
public static ApplicationContext getApplicationContext() {
return context;
}
@Override
public void setApplicationContext(ApplicationContext ac)
throws BeansException {
context = ac;
}
private static final Logger logger = Logger.getLogger(SOAPprocessImpl.class.getName());
private IValidator validator = (IValidator) context.getBean("IValidator"); // context is NULL here
public IRResponse GetBalance(TSSearchParams SearchParams) {
// Some processing logic
}
}
所以问题是,当我通过部署到嵌入式 Tomcat 来运行启动应用程序时,即使在实现 ApplicationContextAware 之后,也没有在 SOAPprocessImpl 类中设置应用程序上下文。我也尝试过自动装配,但这也不起作用。
奇怪的是,我试图查看是否可以在定义了所有 bean 的配置文件中获取 ApplicationContext。这里设置正确。
谁能帮我解决这个问题。我是 Spring Boot 的新手,可能错过了一些配置。提前致谢。
【问题讨论】:
标签: java spring web-services soap spring-boot