我正在运行一个带有spring-boot
的web应用程序,并且必须使用外部连接词,这些连接词使用ContextLoader.getCurrentWebApplicationContext()
来获取一些bean。 但它总是返回null
。 根据spring-boot
文档,父应用程序上下文不是WebApplicationContext
。是否有其他方式通过ContextLoader.getCurrentWebApplicationContext()
访问WebApplicationContext
?ContextLoader.getCurrentWebApplicationContext()总是返回null
在此先感谢!
不幸的是我无法改变它们。我只是可以发出更改请求。它是关于一些通过'''''ContextLoader'''初始化一些bean的自定义servlet。所以只要他们使用'''''ContextLoader'''我就不得不自己实现这些Servlet? – meltac
我想你可以写一个自定义的'ContextLoaderListener'而不是直接使用'SpringBootServletInitializer'或'SpringApplication'。监听器将扩展'ContextLoader'(或现有的监听器),但使用'SpringApplication'加载上下文。这里有一个原型(https://github.com/scratches/spring-boot-legacy/blob/master/src/main/java/org/springframework/boot/legacy/context/web/SpringBootContextLoaderListener.java)if你有兴趣。 –
非常感谢!这将是一个很大的帮助。 – meltac