码迷,mamicode.com
首页 > 其他好文 > 详细

第一讲work(axe)

时间:2018-05-30 15:07:07      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:schema   coding   system   ack   oca   property   interface   private   utf-8   

1,Dao

package com.songyan.Dao;

public interface Axe {
public void chop();
}
package com.songyan.Dao;

public class StoneAxe implements Axe{
    public void chop() {
        System.out.println("axe~~~~");
    }

}

2,service

package com.songyan.Dao;

public class Chinese implements Person{
    private Axe axe;
    
    public Axe getAxe() {
        return axe;
    }

    public void setAxe(Axe axe) {
        this.axe = axe;
    }

    public void useAxe() {
        axe.chop();
        System.out.println("chinese~~~");
    }

}
package com.songyan.Dao;

public interface Person {
public void useAxe();
}

3,配置

<?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="chinese" class="com.songyan.Dao.Chinese">
        <property name="axe" ref="axe"></property>
    </bean>
    <bean id="axe" class="com.songyan.Dao.StoneAxe"></bean>
</beans>

4,测试

package com.songyan.Dao;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "com/songyan/Dao/ApplicationContext.xml");
        Chinese chinese = (Chinese) applicationContext.getBean("chinese");
        chinese.useAxe();
    }
}

 

第一讲work(axe)

标签:schema   coding   system   ack   oca   property   interface   private   utf-8   

原文地址:https://www.cnblogs.com/excellencesy/p/9110790.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!