0%

SPRING2–SPRING第一个程序

1.需要基本jar包

知识点:基本知识点
如何创建一个对象,通过xml配置

1
<bean id=”beanService” class=”com.bean.service.beanServiceImpl”></bean>

其中beanservice是接口,beanServiceImpl是实现类
面试题:spring容器在什么时候创建
spring容器在xml加载时,就创建对象

test测试的方法(说明了ClassPathXmlApplicationContext,FileSystemXmlApplicationContext的差别)

1
2
3
4
5
6
7
8
9
10
@Test
public void test() {
//在src的类目录下
//ApplicationContext applicationContext=new ClassPathXmlApplicationContext(“ApplicationContext.xml”);
//在项目的跟目录下 例如d:spring-demo 放在这目录下
ApplicationContext applicationContext=new FileSystemXmlApplicationContext(“ApplicationContext.xml”);
beanService beanService=(com.bean.service.beanService) applicationContext.getBean(“beanService”);
beanService.add();
beanService.update();
}