spring的helloworld

1、创建web项目

2、引jar包

3、引入日志配置文件
log4j.properties

4、创建java类
public class Person {
private String name;
private Integer age;

public Person() {
    super();
    System.out.println("构造方法被调用");
}
    //getters、setters、toString

}

5、创建bean容器
名字和路径没有特殊要求。
一般配置文件命名为applicationContext-xxx.xml,放在src路径下

<?xml version="1.0" encoding="UTF-8"?>

6、配置bean对象



7、测试用例
public class IOCTest {
@SuppressWarnings(“resource”)
@Test
public void testCreatePerson() {

    //创建容器
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    //查找对象
    Person p = (Person)context.getBean("p");
    
    System.out.println(p);

}

}

是否将当前网页翻译成中文 翻译中… 中英对照

猜你喜欢

转载自blog.csdn.net/anhldd/article/details/84938848
今日推荐