我有以下问题。我的多模块弹簧应用程序在启动时加载了两个不同的上下文。在jsp中使用不同上下文和SpringBeanAutowiringSupport的弹簧
上下文一加载了这段代码片段。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
,并通过Web服务休息
<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。
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
这只允许自动装配主环境中定义的bean。我无法从REST Servlet声明的上下文中自动调用bean。有没有办法让这个上下文在jsp中可用?我知道一种方法是在主要上下文中声明所有的bean,但我希望它们保持分离。
问候, smoothny
在此查看javadoc的ContextLoader http://docs.spring.io/spring/docs/2.5.6/api/org/springframework/web/context/ContextLoader.html#getCurrentWebApplicationContext()。您可以使用“contextConfigLocation”参数配置位置。 – Priyesh