Spring框架搭建(简)

Spring框架搭建(简)

先创建一个web工程,创建时注意选择合适的版本(如图1),然后搭建该web工程所需要的大概框架
在这里插入图片描述(1)
接着为项目添加Spring支持:在项目名称右键菜单选择 “Myeclipse”,然后在二级菜单中选择“Add Spring Capabilities …”。
在这里插入图片描述
接着选择Struts版本Spring 3.1版本,然后勾选需要的library,即前四个,然后下一步默认配置即可。
在这里插入图片描述
接着修改配置文件的命名空间applicationContext.xml,默认命名空间不完整修,命名修改代码如下

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring‐tx‐3.1.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring‐aop‐3.1.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring‐context‐3.1.xsd
	http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
</beans>

然后在web.xml中配置spring的监听器,在项目启动时启动spring。
在这里插入图片描述
代码如下:

<!-- 指定spring配置文件的位置 -->
<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置spring监听器 可以让spring容器随项目的启动而创建,随项目的关闭而销毁 -->
<listener>
		<description>spring监听器</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

接着即可以使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值