public class Main {
public static void main(String[] args){
// //创建HelloWorld的一个对象
// HelloWorld helloWorld = new HelloWorld();
// //为name属性赋值
// helloWorld.setName("atguigu");
//1.创建Spring的IOC容器对象
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.从IOC中获取Bean容器实例
HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
//3.调用hello方法
helloWorld.hello();
}
}
<?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.xsd">
<bean id="helloworld" class="com.spring.beans.HelloWorld">
<property name="name2" value="Spring"></property>
</bean>
</beans>
package com.spring.beans;
public class HelloWorld {
String name;
public void setName(String name) {
this.name = name;
}
public void hello(){
System.out.println("hello:"+name);
}
}
求指教为何创建Spring的IOC容器对象时候出错
跪谢