首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Spring-HelloWorld 学习札记(1)

2012-09-21 
Spring-HelloWorld 学习笔记(1)注:简单演示了Spring最简单的用法。用于自己学习记录。?1、准备:(1)最新版本Ec

Spring-HelloWorld 学习笔记(1)

注:简单演示了Spring最简单的用法。用于自己学习记录。

?

1、准备:

(1)最新版本Eclipse,http://www.eclipse.org/downloads/?

(2)Spring插件:Latest GA release:??? 3.0.5.RELEASE???http://www.springsource.org/download

?包含:spring-framework-3.0.5.RELEASE-with-docs.zip 和spring-framework-3.0.5.RELEASE-dependencies

2、在Eclipse中新建一个 Java Project,命名为HelloSpring;

3、新建一个类:Flower.java

?

package wuyechun.hellosrping.spring;public class Flower { private int number; private String name = "rose"; private String color = "red"; public int getNumber() {  return number; } public void setNumber(int number) {  this.number = number; } public String getName() {  return name; } public void setName(String name) {  this.name = name; } public String getColor() {  return color; } public void setColor(String color) {  this.color = color; }} 

?

?

?4、New —>Other—>Spring—>Spring Bean Configuration File 新建配置文件,命名为:bean.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="flower" name="code">package wuyechun.hellosrping.spring;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;public class ShowFlower { /**  * @param args  */ public static void main(String[] args) {  //  BeanFactory factory=new ClassPathXmlApplicationContext("beans.xml");//   Flower factory=context.getBean("flower",Flower.class);  ApplicationContext context=new FileSystemXmlApplicationContext("src/bean.xml");  Flower flower=context.getBean("flower",Flower.class);  System.out.println("Name:"+flower.getName()+" "+"Color:"+flower.getColor()); }}

?

?

?

?

?

?

?

?

?

热点排行