gpt4 book ai didi

SpringBeanAutowiringSupport 与 WebApplicationContextUtils

转载 作者:行者123 更新时间:2023-12-03 21:29:09 31 4
gpt4 key购买 nike

这是在网络应用程序的上下文中。我的 Impl 类有 JAX-WS 注释,而 @Autowired 注释不起作用。我在检索 Autowired 对象时遇到空指针异常。

找到解决方案,两者都有效:

  1. 扩展 SpringBeanAutowiringSupport 并保持 @Autowired 注释完整。
  2. 使用WebApplicationContextUtils 获取加载bean 的WebapplicationContext。此上下文中的 getBean() 为我提供了所需的 bean。

现在,SpringBeanAutowiringSupport 类的文档在 NOTE 中说"如果有访问 ServletContext 的显式方法,则首选这种方式而不是使用此类。WebApplicationContextUtils 类允许轻松访问基于 ServletContext 的 Spring 根 Web 应用程序上下文。"

这是什么意思?在我的 Web 应用程序中,我没有使用任何 servlet。我的 Web 应用程序也不是唯一的 JAX-WS 应用程序。它是一个带有 SOAP/REST webservicesEJB 的 web 应用程序。

首选哪种方法,为什么?请帮忙。

最佳答案

在 spring 文档中提到扩展 SpringBeanAutoWiringSupport 作为首选方式。这种方法不是更好吗,因为您不必从 webcontext 显式访问 bean?

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/remoting.html#remoting-web-services

关于SpringBeanAutowiringSupport 与 WebApplicationContextUtils,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863056/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com