• spring4笔记----spring4设值注入



    2个接口

    package com.ij34.servce;
    
    public interface people {
           public void cut();
      
    }
    package com.ij34.servce;
    
    public interface root {
      public String chop();
    }

    实现上面的接口

    package com.ij34.web;
    
    import com.ij34.servce.people;
    import com.ij34.servce.root;
    
    public class chinese implements people{
        private root dog;
    
    
    
        public root getDog() {
            return dog;
        }
    
    
    
        public void setDog(root dog) {
            this.dog = dog;
        }
    package com.ij34.web;
    
    import com.ij34.servce.root;
    
    public class stonechop implements root{
    
        @Override
        public String chop() {
            // TODO Auto-generated method stub
            return "使用石头";
        }
      
    }
    package com.ij34.web;
    
    import com.ij34.servce.root;
    
    public class ironchop implements root{
    
        @Override
        public String chop() {
            // TODO Auto-generated method stub
            return "使用铁斧";
        }
    
    }

    beans

    <?xml version="1.0" encoding="GBK"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
    
     <bean id="chinese" class="com.ij34.web.chinese">     //  是chinese不是people
     <property name="dog" ref="iron"></property>
     </bean>
     <bean id="stone" class="com.ij34.web.stonechop"></bean>
     <bean id="iron" class="com.ij34.web.ironchop"></bean>
    </beans>

    加载bean,实现调用实例

    package com.ij34.bean;
    
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import com.ij34.servce.people;
    
    public class test {
    
        
        public static void main(String[] args) throws Exception{
            // TODO Auto-generated method stub
            @SuppressWarnings("resource")
            ApplicationContext app=new ClassPathXmlApplicationContext("beans.xml");
            people p= app.getBean("chinese",people.class);
             p.cut();
        }
    
    }
  • 相关阅读:
    网页性能分析
    vue学习图解
    px-em-rem单位转换
    呼啦圈(keyframes和transform结合)
    菜单栏鼠标经过伸缩效果
    携程transform放大效果
    浮动布局demo
    倒圆角艺术
    伪类分类
    ingress-nginx 添加https证书
  • 原文地址:https://www.cnblogs.com/tk55/p/6498378.html
Copyright © 2020-2023  润新知