标签: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(); } }
标签:schema coding system ack oca property interface private utf-8
原文地址:https://www.cnblogs.com/excellencesy/p/9110790.html