新建java project,添加文件HelloSpring.java.

HelloSpring.java

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloSpring {

	/**
	 * @param args
	 */
	public void sayHello()
	{
		System.out.print("Hello Spring Bean");
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub				
		ClassPathXmlApplicationContext context= new ClassPathXmlApplicationContext("HelloSpring.xml");
		HelloSpring myBean = (HelloSpring) context.getBean("HelloSpringBean");
		myBean.sayHello();
	}
}

添加HelloSpring.xml。

HelloSpring.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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="HelloSpringBean"
     class="HelloSpring" />
</beans>.

Project->properties->Java build path->Libraries->add external jars

引用springframework相关jars,以及org.apache.commons.logging




posted on 2013-03-24 22:56  #hanhui  阅读(136)  评论(0)    收藏  举报