02-Spring之環境配置(Spring+Struts2,Eclipse)
2011-07-27 11:30
369 查看
說明:
1、代碼顏色為#ff6600
一、軟件要求
Spring: Srping 2.5.6版本 下載地址:http://www.springsource.com/download/community?sid=1243024 下載先註冊下,隨便填寫就可以了。
注,我下載的是spring-framework-2.5.6-with-docs.zip ,不是spring-framework-2.5.6.SEC02-with-docs.zip
二、環境配置
此環境配置是結合Struts2來完成的,即Spring+Struts的整合,單獨配置將在以後描述。Struts的設置是接上篇文章的結果來繼續的。下麵是Spring的環境配置。
1、解壓spring-framework-2.5.6-with-docs.zip文件
2、打開解壓后的文件夾,選擇 spring.jar 將其放置/WEB-INF/lib目錄下。
三、改進第一篇文章,以Spring+Struts2實現。
1、文件介紹
applicationContext.xml Spring的默認配置文件。
步驟:
a、打開/WEB-INF/web.xml文件,在<web-app></web-app>中追加以下內容。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
b、新建文件applicationContext.xml文件,其位置在/WEB-INF/applicationContext.xml,位置與web.xml相同。注:這與struts.xml的位置是不同的。在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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="loginSpring" class="com.UserAction">
</bean>
</beans>
關於applicationContext.xml內容配置將在後續文章中講到。
c、打開/src/struts.xml文件,將action標籤做了一點修改,比較內容如下:
原來的內容:
<action name="login" class="com.test.UserAction">
<result>/success.jsp</result>
</action>
修改后的內容:
<action name="login" class="loginSpring">
<result>/success.jsp</result>
</action>
說明:修改后的標籤action的屬性class值是loginSpring 其是與applicationContext.xml中的bean標籤的name屬性值相一致。
四、測試
Sping的簡單配置已經完成,現在可以向第一篇文章的測試方式一樣,在此不再贅述。
1、代碼顏色為#ff6600
一、軟件要求
Spring: Srping 2.5.6版本 下載地址:http://www.springsource.com/download/community?sid=1243024 下載先註冊下,隨便填寫就可以了。
注,我下載的是spring-framework-2.5.6-with-docs.zip ,不是spring-framework-2.5.6.SEC02-with-docs.zip
二、環境配置
此環境配置是結合Struts2來完成的,即Spring+Struts的整合,單獨配置將在以後描述。Struts的設置是接上篇文章的結果來繼續的。下麵是Spring的環境配置。
1、解壓spring-framework-2.5.6-with-docs.zip文件
2、打開解壓后的文件夾,選擇 spring.jar 將其放置/WEB-INF/lib目錄下。
三、改進第一篇文章,以Spring+Struts2實現。
1、文件介紹
applicationContext.xml Spring的默認配置文件。
步驟:
a、打開/WEB-INF/web.xml文件,在<web-app></web-app>中追加以下內容。
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
b、新建文件applicationContext.xml文件,其位置在/WEB-INF/applicationContext.xml,位置與web.xml相同。注:這與struts.xml的位置是不同的。在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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="loginSpring" class="com.UserAction">
</bean>
</beans>
關於applicationContext.xml內容配置將在後續文章中講到。
c、打開/src/struts.xml文件,將action標籤做了一點修改,比較內容如下:
原來的內容:
<action name="login" class="com.test.UserAction">
<result>/success.jsp</result>
</action>
修改后的內容:
<action name="login" class="loginSpring">
<result>/success.jsp</result>
</action>
說明:修改后的標籤action的屬性class值是loginSpring 其是與applicationContext.xml中的bean標籤的name屬性值相一致。
四、測試
Sping的簡單配置已經完成,現在可以向第一篇文章的測試方式一樣,在此不再贅述。
相关文章推荐
- SSH与SSM学习之SSH整合02——单独配置Spring容器
- 在eclipse中配置一个简单的spring入门项目
- 02-spring学习-配置bean
- Eclipse下配置spring应用
- eclipse配置Struts2、Hibernate3、Spring2.5范例
- eclipse开发spring配置文件xml代码不提示的解决办法
- eclipse中spring配置文件的自动提示和命名空间的添加
- Spring JPA 配置文件在Eclipse下报错
- 在eclipse中配置spring工程
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之一 : Maven的pom.xml环境配置及注意方面
- (02) SpringBoot 配置文件使用
- 配置spring+eclipse
- eclipse安装spring tool suite插件便于xml配置文件选择命名空间添加
- Spring配置文件中属性值不能提示的解决办法(eclipse添加xsd文件)
- Eclipse+maven配置SSM(Spring+SpringMVC+mybatis)
- 让Eclipse中spring的xml配置文件出现属性和类提示
- Day02:②在Eclipse上配置Spring mybatis
- eclipse 中spring项目的xml配置打开方式里 找不到Namespaces
- eclipse配置springloaded实现热部署
- J2EE之Eclipse配置Spring插件及Spring建立HelloWord