gpt4 book ai didi

spring - ContextLoader.getCurrentWebApplicationContext() 总是返回 null

转载 作者:行者123 更新时间:2023-12-05 09:23:23 26 4
gpt4 key购买 nike

我正在使用 spring-boot 运行网络应用程序,并且必须使用使用 ContextLoader.getCurrentWebApplicationContext() 从中获取一些 bean 的外部工件。但它始终返回 null。根据 spring-boot 文档,父应用程序上下文不是 WebApplicationContext。有没有其他方法可以通过 ContextLoader.getCurrentWebApplicationContext() 访问 WebApplicationContext

提前致谢!

最佳答案

ContextLoader 并不真正适用于 Spring Boot 应用程序(或任何具有 Servlet 3.0 动态初始化的应用程序)。 Spring Boot 确实设置了 ServletContext 以便 WebApplicationContextUtils 可以找到 Web 上下文。您的外部工件确实不应该使用 ContextLoader 静态方法,因为它会假设应用程序的部署方式。你能改变它们吗?或者想出另一种方法来设置它们的状态?

关于spring - ContextLoader.getCurrentWebApplicationContext() 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167912/

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