[Seasar-user:4265] Re: dicon�ե����뤫��init�ե������ɤ߹���

Hideaki Suzuki [E-MAIL ADDRESS DELETED]
2006ǯ 8�� 5�� (��) 15:37:00 JST


����(belltree)�Ǥ���

��­�ʼ�­���ˤǤ��� ^^;;;

�ɤ����Ƥ�properties�ե����뤸��ʤ��㥤�䡪�Ȥ������ˤϡ�
�������ˡ�⤢��ޤ���

��properties�ե�����: [org/seasar/trick/resource/env.properties]
jdbc.driver.class=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://localhost:9001
jdbc.user=sa
jdbc.password=

���Ķ�������dicon�ե�����: [org/seasar/trick/resource/env.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="ENV">
    @org.seasar.framework.util.ResourceUtil@
      getProperties("org/seasar/trick/resource/env.properties")
  </component>
</components>

������¦dicon�ե�����: [org/seasar/trick/resource/env.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>
  <include path="org/seasar/trick/resource/env.dicon"/>
  <component name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">ENV["jdbc.driver.class"]</property>
    <property name="url">ENV["jdbc.url"]</property>
    <property name="username">ENV["jdbc.user"]</property>
    <property name="password">ENV["jdbc.password"]</property>
  </component>
</components>

�ޤ���Spring��
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
�ߤ����ˡ�ʣ����properties�ե��������ꤷ�ơ��御���롼��ǡ�
�ץ��ѥƥ��ͤ򥪡��С��饤�ɤ��������ˤϡ�����ʴ����ǤǤ��ޤ���
  <component name="ENV" class="java.util.Properties">
    <initMethod name="load">
      <arg>
        @org.seasar.framework.util.ResourceUtil@
          getResourceAsStream("org/seasar/trick/resource/env1.properties")
      </arg>
    </initMethod>
    <initMethod name="load">
      <arg>
        @org.seasar.framework.util.ResourceUtil@
          getResourceAsStream("org/seasar/trick/resource/env2.properties")
      </arg>
    </initMethod>
  </component>


PropertyPlaceholderConfigurer��ignoreResourceNotFound�ץ��ѥƥ���true��
���ꤷ�����ε�ư��Ƹ�����ˤϡ��⤦1����ɬ�פ����
���Ȥ��С�����ʴ����Υ��饹���äơ�

package org.seasar.trick.resource;

import java.io.IOException;
import java.util.Properties;

import org.seasar.framework.exception.IORuntimeException;
import org.seasar.framework.exception.ResourceNotFoundRuntimeException;
import org.seasar.framework.util.ResourceUtil;

public class PropertiesMixer extends Properties {

	private static final long serialVersionUID = -7578337136933134477L;

	private boolean ignoreResourceNotFound = false;
	
	public void ignoreResourceNotFound() {
		ignoreResourceNotFound = true;
	}
	
	public void load(String path) {
		if (!ResourceUtil.isExist(path)) {
			if (ignoreResourceNotFound) {
				return;
			} else {
				throw new ResourceNotFoundRuntimeException(path);
			}
		}
		try {
			load(ResourceUtil.getResourceAsStream(path));
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
	
}

����ʴ��������ꤹ��Ȥ���

  <component name="ENV" class="org.seasar.trick.resource.PropertiesMixer">
    <initMethod name="ignoreResourceNotFound"/>
    <initMethod name="load"><arg>"org/seasar/trick/resource/env1.properties"</arg></initMethod>
    <initMethod name="load"><arg>"org/seasar/trick/resource/env2.properties"</arg></initMethod>
    <initMethod name="load"><arg>"org/seasar/trick/resource/env3.properties"</arg></initMethod>
  </component>


���ʤߤ�OGNL��Map�񼰤�Ȥäơ�����ʴ����ǻ��ꤹ�뤳�Ȥ��ǽ�Ǥ���
�ͤμ�����ˡ�ϡ��嵭��Ʊ���Ǥ���
  <component name="ENV">
    #{
      "jdbc.driver.class" : "org.hsqldb.jdbcDriver",
      "jdbc.url"          : "jdbc:hsqldb:hsql://localhost:9001",
      "jdbc.user"         : "sa",
      "jdbc.password"     : ""
    }
  </component>

�����ͤޤǤˡ�����

p.s.
�嵭�����ɤϤ���ͳ�ˤ����Ѳ�������

/** 
 * @auther Hideaki Suzuki
 * @contact [E-MAIL ADDRESS DELETED]
 */




Seasar-user �᡼��󥰥ꥹ�Ȥΰ���