創(chuàng)建?Spring的IOC容器對象時候出錯
public class Main {
?? ?
?? ?public static void main(String[] args){
?? ??? ?
?? ??? ?
//?? ??? ?//創(chuàng)建HelloWorld的一個對象
//?? ??? ?HelloWorld helloWorld = new HelloWorld();
//?? ??? ?//為name屬性賦值
//?? ??? ?helloWorld.setName("atguigu");
?? ??? ?
?? ??? ?//1.創(chuàng)建Spring的IOC容器對象
?? ??? ?ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
?? ??? ?
?? ??? ?
?? ??? ?//2.從IOC中獲取Bean容器實例
?? ??? ?HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
?? ??? ?
?? ??? ?//3.調(diào)用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);
?? ??? ?
???? }
}
求指教為何創(chuàng)建Spring的IOC容器對象時候出錯
跪謝