Seasar2の履歴
DIコンテナの例
Player.java
import java.io.File; import org.seasar.framework.container.S2Container; import org.seasar.framework.container.SingletonS2Container; import org.seasar.framework.container.factory.SingletonS2ContainerFactory; public class Player implements Human{ private static final String PATH = "aki/test/test.dicon"; private static Player aa; public static void main(String[] args) { SingletonS2ContainerFactory.setConfigPath(PATH); SingletonS2ContainerFactory.init(); S2Container container = SingletonS2ContainerFactory.getContainer(); Human hoge = SingletonS2Container.getComponent("hoge"); hoge.say(); } private String name; private int rep = 1; public Player(String name){ this.name = name; } public void say(){ StringBuffer sb = new StringBuffer(); for (int i = 0; i < rep; i++){ sb.append("hello! "); } System.out.println(name + " says " + sb); } public void setRepeat(int i){ rep = i; } }
Human.java
public interface Human { public void say(); }
test.dicon
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" "http://www.seasar.org/dtd/components24.dtd"> <components> <component name="hoge" class="aki.test.Player"> <arg>"hogehoge"</arg> <property name="repeat">4</property> </component> </components>