SpringBeanAutowiringSupport与Web应用程序上下文
这是web应用程序的上下文。我的Impl类具有SpringBeanAutowiringSupport与Web应用程序上下文,spring,jax-ws,autowired,Spring,Jax Ws,Autowired,这是web应用程序的上下文。我的Impl类具有JAX-WS注释,并且@Autowired注释不起作用。 检索自动连线对象时出现空指针异常 找到解决方案,两者都有效: 扩展SpringBeanAutowiringSupport并保持@Autowired注释完整 使用webapplicationcontextils获取加载bean的WebapplicationContext。此上下文中的getBean()为我提供了所需的bean 现在,SpringBeanAutowiringSupport类的文档在
JAX-WS
注释,并且@Autowired
注释不起作用。
检索自动连线对象时出现空指针异常
找到解决方案,两者都有效:
SpringBeanAutowiringSupport
并保持@Autowired
注释完整webapplicationcontextils
获取加载bean的WebapplicationContext
。此上下文中的getBean()为我提供了所需的beanSpringBeanAutowiringSupport
类的文档在注释中说
如果存在访问ServletContext的显式方法,请选择这种方法,而不要使用此类。WebApplicationContextUtils类允许基于ServletContext轻松访问Spring根web应用程序上下文。
这是什么意思?在我的web应用程序中,我没有使用任何servlet。我的web应用程序也不是唯一的JAX-WS
应用程序。它是一个web应用程序,具有SOAP/RESTWebServices
和EJB
选择哪种方法?为什么?请提供帮助。在spring文档中,扩展SpringBeanAutoWiringSupport是首选的方式。由于不必从webcontext显式访问bean,这种方法不是也更好吗
一个很好的使用示例是,当您有一个web服务,并且希望自动连接您制作的许多其他SpringBean时。这看起来比使用上下文Utils更优雅
@WebService(targetNamespace = "http://yada/yada", endpointInterface = "com.ISomeWS", serviceName = "SomeWS")
public class SomeWS extends SpringBeanAutowiringSupport implements ISomeWS {
@Autowired ISpringService springService;
public WSImportResponse processXMLContent(SomeType xmlContent) throws Exception {
springService.say("Hello");
}
}
谢谢你,约翰。它看起来确实更好,更容易实现。但是,我想了解文件中提到的注释的意图: