JAVA Spring HelloWord实现

IDE:IntelliJ IDEA 2017

HelloWord.java

package com.xidian.edu;

public class HelloWorld {
    private String name;
    public void setName(String name){
        this.name=name;
    }
    public void printName(){
        System.out.println("Spring Hello:"+this.name);
    }
}

applicationContext.xml



    
        
    

AppMain.java

package com.xidian.edu;

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

public class AppMain {
    public static void main(String args[]){
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "applicationContext.xml");
        HelloWorld obj = (HelloWorld) context.getBean("helloBean");
        obj.printName();
    }
}

目录结构:

JAVA Spring HelloWord实现_第1张图片



运行结果:

JAVA Spring HelloWord实现_第2张图片




你可能感兴趣的:(JAVA,三大框架SSH)