文章目录
Spring 整合 Servlet
一、 Jar 包依赖
Spring 核心容器模块:
spring-beans-5.2.7.RELEASE.jar
spring-context-5.2.7.RELEASE.jar
spring-core-5.2.7.RELEASE.jar
spring-expression-5.2.7.RELEASE.jar
Commons-Loggin 日志:
commons-logging-1.2.jar
Spring AOP 模块:
spring-aop-5.2.7.RELEASE.jar
SpringWeb 模块:
spring-web-5.2.7.RELEASE.jar
Servlet:
servlet-api.jar
二、 搭建环境
1、创建 Web 项目

2、添加 Spring 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
</beans>
3、 在 Web 项目中启动 Spring 框架
在 Web 项目中需要在 web.xml 文件中配置启动 Spring 框架的监听器。用于启动 Spring框架。
修改 web.xml 文件:

本文详细介绍了如何将Spring与Servlet整合,包括所需Jar包依赖、环境搭建步骤,如创建Web项目、配置Spring启动监听器以及在Servlet中获取Bean对象。通过实例展示了业务层、Servlet和持久层的创建过程。
最低0.47元/天 解锁文章
917

被折叠的 条评论
为什么被折叠?



