第一讲work(axe)
Posted song.yan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一讲work(axe)相关的知识,希望对你有一定的参考价值。
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)的主要内容,如果未能解决你的问题,请参考以下文章