Spring web app. One war multiple application context
I searched for a while but can't manage to find a proper solution to my problem.
I have one WAR web application and I want 2 spring applications running in it one for the web-part, one running scheduled task. Both applications share a lot of beans so I would like that those two applications share some beans instance.
I'd like to split my contexts in:
-shared-context.xml
-web-context.xml
-task-context.xml
Web-context and task-context must be isolated and not see each other. They need to create a few beans that are the same but have different configs.
Is this possible? And how should I do it?
I tried first to put <import resource="classpath:shared-context.xml" />
in both web-context and task context and to configure my web.xml as
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>web-context.xml task-context.xml</param-value>
</context-param>
but the problem is that there is no isolation between web and task. They all share all the beans even the one defined in web-context.xml and task-context.xml
For info here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-context.xml /WEB-INF/task-context.xml</param-value>
</context-param>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.gwtrpcspring.RemoteServiceDispatcher</servlet-class>
</servlet>
<servlet>
<servlet-name>contentDownloadServlet</servlet-name>
<servlet-class>ch.olator.servlet.MyContentDownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.rpc</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>contentDownloadServlet</servlet-name>
<url-pattern>/download</url-pattern>
</servlet-mapping>
... some irrelevant filters ...
</web-app>
UPDATED
-To make things clearer I need this isolation between task and web because the task-context which is used to run scheduled task to define some beans that are in web-context but differently. Eg I have scoped-session beans that are in web-context but I need to define them differently for the tasks as scheduled task can't use scoped-session beans.
you can use the import tag
in web-context.xml:
<import resource="classpath:shared-context.xml" />
<import resource="classpath:task-context.xml" />
链接地址: http://www.djcxy.com/p/38928.html
上一篇: 替换后台任务的作用域会话bean