首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring学习(1)一个简单的Spring应用程序

2012-07-25 
Spring学习(一)一个简单的Spring应用程序1、在MyEclipse中创建一个web project,命名为spring2、将spring相关

Spring学习(一)一个简单的Spring应用程序
1、在MyEclipse中创建一个web project,命名为spring
2、将spring相关的jar包放到lib目录下
2、创建con.gc.action包,com.gc.test包和com.gc.impl包。
3、创建HelloWorld类,如下:
package com.gc.action;

public class HelloWorld {

private String msg;

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

}
4、提供config.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"
       default-lazy-init="true">
    <bean id="helloWorld" 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"
       default-lazy-init="true">
    <bean id="helloWorld" class="com.gc.action.EhHello">
       <property name="msg">
         <value>gf</value>
       </property>
    </bean>
</beans>
由此看到只修改config的配置文件,就可以修改程序的运行结果,以上功能展示Spring的核心即IOC。

热点排行