1. 程式人生 > >03.Spring-將物件存放在容器裡面

03.Spring-將物件存放在容器裡面

在這裡插入圖片描述

package vc.helloworld.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import vc.helloworld.bean.User;

public class TestDemo {
	@Test
	public void fun1() {
		// 1.首先要把容器創建出來,
		ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("ApplicationContext.xml"); // 2.向容器裡面獲取到user物件 User user = (User) applicationContext.getBean("user"); // 3.列印獲取到的user物件. System.out.println(user); } }