开发者

Loading spring context in web application after some servlet

We need to load the spring application context in our web application after one of our servlets is initialized, so I wonder what is the best way to do it?

I know that it's recommended to use the listener in web.xml, but it's obviously not good for us because in this case the context will be loaded before the first servlet. I saw that there was this class - ContextLoaderServet - in Spring 2.5, but it's abse开发者_如何学Pythonnt in Spring 3.0. So I guess we should write some dummy servlet ourselves with the sole purpose of loading the context? Is there any better way?

Thanks.


OK, so if you have this legacy servlet that sets stuff up, then you will need to persuade the Spring servlet to load after it.

This is straightforward - use Spring's DispatcherServlet to load the Spring context, and use the standard <load-on-startup> in web.xml to dictate the startup order, e.g.

<servlet>
  <servlet-name>LegacyServlet</servlet-name>
  <servlet-class>com.xy.LegacyServlet</servlet-class>
  <load-on-startup>0</load-on-startup>
</servlet>


<servlet>
  <servlet-name>SpringServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜