1.5 环境检测 新建一个HelloWorld类 package com.lbh.spring.beans; public class HelloWorld { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; System.out.println("setName="+name); } public void name() { System.out.println("hello:"+name); } public HelloWorld() { System.out.println("HelloWorld constructor..."); } } 新建一个applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd"> <!-- 配置bean --> <bean id="helloworld" class="com.lbh.spring.beans.HelloWorld"> <property name="name" value="111"></property> </bean> </beans> 新建main方法进行输出测试 package com.lbh.spring.beans; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; public class Main { /** * @param args */ public static void main(String[] args) { // HelloWorld helloworld = new HelloWorld(); // helloworld.setName("lbh"); // helloworld.name(); //1.注册配置文件2.获取bean 3.调用bean方法 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); HelloWorld helloworld = (HelloWorld) ctx.getBean("helloworld"); helloworld.name(); } }