为了账号安全,请及时绑定邮箱和手机立即绑定

创建​Spring的IOC容器对象时候出错

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容器对象时候出错


跪谢

正在回答

1 回答

举报

0/150
提交
取消

创建​Spring的IOC容器对象时候出错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信