时间:2015-06-08 10:30 来源: 我爱IT技术网 作者:52ij
eclipse 安装spring开发包:https://spring.io/tools/sts/all
并安装
下载日志记录器: http://mvnrepository.com/artifact/commons-logging/commons-logging
下载spring的包:http://repo.springsource.org/libs-release-local/org/springframework/spring/4.0.0.RELEASE/spring-framework-4.0.0.RELEASE-dist.zip
新建HelloWorld class
package edu.spring.beans;
public class HelloWorld {
private String name;
public void setNamex(String name){
this.name=name;
}
public void hello(){
System.out.println("hello "+name);
}
}新建配置文件appContext.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.xsd"> <bean id="helloworld" class="edu.spring.beans.HelloWorld"> <property name="namex" value="Spring"></property></bean> </beans>
新建Main class
public class Main {
public static void main(String[] args) {
ApplicationContext ctx=new ClassPathXmlApplicationContext("appContext.xml");
HelloWorld helloworld=(HelloWorld) ctx.getBean("helloworld");
helloworld.hello();
}
}结果:
hello Spring
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
