zoukankan      html  css  js  c++  java
  • zbb20170216_spring_ioc

    1、结构图

    2、class文件

    MyIoc.java

    package com.zbb.ioc;
    
    public class MyIoc {
        MyService myService;
        public void ioc(){
            myService.service();
        }
        /*public MyIoc(MyService myService) {
            super();
            this.myService = myService;
        }*/
        public MyService getMyService() {
            return myService;
        }
        public void setMyService(MyService myService) {
            this.myService = myService;
        }
        
    }

    MyService.java

    package com.zbb.ioc;
    
    public class MyService {
    public void service(){
        System.out.println("service");
    }
    }

    MyTest.java

    package com.zbb.ioc;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class MyTest {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
            MyIoc bean = (MyIoc)classPathXmlApplicationContext.getBean("myIoc");
            bean.ioc();
        }
        
    }

    3、配置文件

    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" xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
        <!-- 构造器注入 -->
        <!-- 
        <bean id="myIoc" class="com.zbb.ioc.MyIoc">
            <constructor-arg>
                <bean class="com.zbb.ioc.MyService"/>
            </constructor-arg>
        </bean>
         -->
         <!-- setter方法注入 -->
         <bean id="myIoc" class="com.zbb.ioc.MyIoc" >
             <property name="myService" >
                 <ref bean="myService"/>
             </property>
         </bean>
         <bean id="myService" class="com.zbb.ioc.MyService" />
    </beans>

  • 相关阅读:
    BZOJ 4033: [HAOI2015]树上染色 (树形DP)
    BZOJ 1820: [JSOI2010]Express Service 快递服务 DP
    BZOJ 4664: Count 插块DP
    BZOJ 1899: [Zjoi2004]Lunch 午餐 DP
    BZOJ 4559 [JLoi2016]成绩比较 (DP+拉格朗日插值)
    BZOJ1485 [HNOI2009] 有趣的数列 (卡特兰数)
    BZOJ 2111 / Luogu P2606 [ZJOI2010]排列计数
    20190915模拟赛
    深海机器人问题
    太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/super-admin/p/6431393.html
Copyright © 2011-2022 走看看