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。