Spring与Web框架集成:核心概念与实践
1. 核心概念基础
在基于Servlet的Web应用程序中, ServletContext
是存储与应用相关数据的地方。每个基于Servlet的应用程序都有一个唯一的 ServletContext
对象,可用于存储配置数据等信息。任何在应用中声明的Servlet都可以通过 ServletRequest
、 ServletResponse
、 ServletConfig
和 FilterConfig
等 javax.servlet
特定类型来访问 ServletContext
。在开发Web应用时,Spring也会将应用上下文存储在 ServletContext
中。
示例中使用了 org.springframework.prospring.ch14.OrderService
接口,该接口仅声明了一个方法:
public Order getOrder(String orderId);
在应用中,我们实现了 OrderService
并在应用上下文(位于 /WEB-INF/applicationContext.xml
)中进行定义: