标签:机制 对组 区别 name 流程 初始化 依赖注入 actor another
public class MyBusniessObject{
private DataSource ds;
private MyCollaborator myCollaborator;
public MyBusnissObject(){
Context ctx = null;
try{
ctx = new InitialContext();
ds = (DataSource) ctx.lookup(“java:comp/env/dataSourceName”);
myCollaborator =
(MyCollaborator) ctx.lookup(“java:comp/env/myCollaboratorName”);
}……
|
package com.zj.ioc.di;
public class Content {
public void BusniessContent(){
System.out.println("do business");
}
public void AnotherBusniessContent(){
System.out.println("do another business");
}
}
|
package com.zj.ioc.di.ctor;
import com.zj.ioc.di.Content;
public class MyBusiness {
private Content myContent;
public MyBusiness(Content content) {
myContent = content;
}
public void doBusiness(){
myContent.BusniessContent();
}
public void doAnotherBusiness(){
myContent.AnotherBusniessContent();
}
}
|
package com.zj.ioc.di.set;
import com.zj.ioc.di.Content;
public class MyBusiness {
private Content myContent;
public void setContent(Content content) {
myContent = content;
}
public void doBusiness(){
myContent.BusniessContent();
}
public void doAnotherBusiness(){
myContent.AnotherBusniessContent();
}
}
|
package com.zj.ioc.di.iface;
import com.zj.ioc.di.Content;
public interface InContent {
void createContent(Content content);
}
|
package com.zj.ioc.di.iface;
import com.zj.ioc.di.Content;
public class MyBusiness implements InContent{
private Content myContent;
public void createContent(Content content) {
myContent = content;
}
public void doBusniess(){
myContent.BusniessContent();
}
public void doAnotherBusniess(){
myContent.AnotherBusniessContent();
}
}
|
public static void main(String[] args) throws Exception{
//get the bean factory
BeanFactory factory = getBeanFactory();
MessageRender mr = (MessageRender) factory.getBean(“renderer”);
mr.render();
}
|
本文出自 “i张俊” 博客,请务必保留此出处http://zhangjunhd.blog.51cto.com/113473/126530
标签:机制 对组 区别 name 流程 初始化 依赖注入 actor another
原文地址:http://www.cnblogs.com/zzmher/p/7499125.html