分类: Java
2008-11-26 15:14:05
1.IHelloWorld接口
package org.tie.seasar1.service;
public interface IHelloWorld {
public void sayHello();
public void constructDI();
public void seterDI();
public void methodDI();
}
2.IHelloWorld接口的实现
package org.tie.seasar1.service.impl;
import org.tie.seasar1.service.IHelloWorld;
public class HelloWorld implements IHelloWorld {
private String msg1;
private String msg2;
private String msg3;
public String getMsg2() {
return msg2;
}
public void setMsg2(String msg2) {
this.msg2 = msg2;
}
public HelloWorld(String msg1) {
super();
this.msg1 = msg1;
}
public void sayHello() {
System.out.println("hello world");
}
public void constructDI() {
System.out.println(msg1);
}
public void seterDI() {
System.out.println(msg2);
}
public void init(String msg3) {
this.msg3 = msg3;
}
public void methodDI(){
System.out.println(msg3);
}
}
3.客户端测试类
package org.tie.seasar1.client;
import org.apache.log4j.Logger;
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import org.tie.seasar1.service.impl.HelloWorld;
public class HelloWorldClient {
private static final Logger log = Logger.getLogger(HelloWorldClient.class);
private static final String PATH = "dicon/helloworld.dicon";
public static void main(String[] args) {
S2Container container = S2ContainerFactory.create(PATH);
container.init();
HelloWorld helloWorld = (HelloWorld) container
.getComponent("helloWorld");
helloWorld.sayHello();
helloWorld.constructDI();
helloWorld.seterDI();
helloWorld.methodDI();
log.info("quick start");
}
}
4.DI配置文件:helloworld.dicon
"">