1. 程式人生 > >Spring 基礎

Spring 基礎

實例 args ext out get context ioc text string

Helloworld.class

public class Helloworld {
        private String name;

    public void setName(String name) {
        System.out.println("setName:"+name);
        this.name = name;
    }

    public void  hello(){
        System.out.println("hello:"+name);
    }
}

輸出

    public static void main(String[] args) {
//        Helloworld helloworld = new Helloworld();
//        helloworld.setName("tangsan");
//        helloworld.hello();

        //1.創建Spring的IOC容器對象
        ApplicationContext context =
                new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.從IOC獲取 Bean 實例
        Helloworld hello = (Helloworld)context.getBean("helloWorld");
         hello.hello();
    }

Spring 基礎