我遇到以下问题。我的多模块 Spring 应用程序在启动时加载两个不同的上下文。
上下文一已加载此代码片段。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
另一个通过其余网络服务
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/components_webservice.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
现在我使用此命令获得了一个 jsp,以便在 jsp 中使用 Autowiring 的 bean。
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
这只使得 Autowiring 在主上下文中定义的bean成为可能。我无法从 REST Servlet 声明的上下文中 Autowiring bean。有没有办法让这个上下文在jsp中可用?我知道一种方法是在主上下文中声明所有 bean,但我希望它们保持分离。
您好, 平滑
最佳答案
不要在 jsp 中放入任何逻辑。 Autowiring Controller 中的字段并将生成的值传递给模型。
关于java - Spring在jsp中使用不同的上下文和SpringBeanAutowiringSupport,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24756321/