加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Bean的实例化

发布时间:2020-12-16 23:36:44 所属栏目:百科 来源:网络整理
导读:一.构造器实例化 ? ? ? One.class类: public class One { public void say(){ System.out.println("我是构造器实例化"); }} applicationContext.xml: ?xml version="1.0" encoding="UTF-8"?beans xmlns="http://www.springframework.org/schema/beans" xmln

一.构造器实例化

? ? ? One.class类:

public class One {
    public void say(){
        System.out.println("我是构造器实例化");
    }
}

  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 id="one" class="cn.chauncey.ioc.One"/>
</beans>

  Test.class测试类:

public class OneTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        One one = (One) applicationContext.getBean("one");
        one.say();
    }
}

  运行结果:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读