接口类
public interface oneinterface {
String hello(String word);
}
接口实现类
public class interfaceimp implements oneinterface {
@Override
public String hello(String word){
return("hello "+word);
}
}
不用bean需要创建实例:
public static void main(String[] args) {
oneinterface oif = new interfaceimp();
System.out.println(oif.hello("yjc"));
}
使用bean管理实例:
xml文件添加bean配置:
<bean id="nihao" class="interfaceimp"> </bean>
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring-ioc.xml");
interfaceimp in = (interfaceimp)context.getBean("nihao");
System.out.println(in.hello("yjc"));
}
网友评论