S eda1a14b50ee24bcab19b62f40858e76 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



    
      "hogehoge"
      4
    

もしかして

    他の人の「Seasar2」

    S eda1a14b50ee24bcab19b62f40858e76

    無所属ソフトウェアエンジニア

    (1722words)

    最新

      最新エントリ

        関連ツイート