你的servlet可以使用WebApplicationContextUtils来获取应用程序上下文,但是你的servlet代码将直接依赖于Spring framework。
另一个解决方案是配置应用程序上下文,以将Spring bean作为属性导出到servlet上下文:
<bean > <property name="attributes"> <map> <entry key="jobbie" value-ref="springifiedJobbie"/> </map> </property></bean>
你的servlet可以使用以下方法从servlet上下文中检索Bean:
SpringifiedJobbie jobbie = (SpringifiedJobbie) getServletContext().getAttribute("jobbie");


