本番環境と開発環境で別の値を使用したい設定値の持ち方
方法はいろいろあると思いますが、最近お気に入りなのはdiconファイルに持ってしまう方法。
diconファイルは サフィックスをつけることで env.txtに書いた環境にあわせて自動的に読込むファイルが変わるので便利です。例えば、
・本番環境用 appConfig_webRel.dicon
<components> <component name="generalConfig" class="org.seasar.framework.beans.util.BeanMap"> #@org.seasar.framework.beans.util.BeanMap@{ "includeJquery" : false, "baseCommonDir" : "/common" } </component> </components>
・開発環境用 appConfig.dicon
<components> <component name="generalConfig" class="org.seasar.framework.beans.util.BeanMap"> #@org.seasar.framework.beans.util.BeanMap@{ "includeJquery" : true, "baseCommonDir" : "../common" } </component> </components>
とかやっておいて、使うクラスでは
class Hoge { @Resource protected BeanMap generalConfig; }
のようにDIしてあげる。
本番環境をビルドするときはenv.txtをwebRelにしておけばよいわけです。
ところでDIするプロパティにつけるアノテーションは @Resourceと@Binding どちらが本筋なんでしょうか。。。