MyBatisのConfigをJava側で動的に書き換えられないか調べてみた。
結果できなかったんだけど、備忘録として。
org.apache.ibatis.session.Configuration
に値を突っ込むことでどうにかなりそう?
configuration.getVariables().put("global_param", "123");
できない。。
SqlSessionFactoryとかSqlSessionTemplateはAutowiredできるので、SQLの発行直前にConfigを引きずり出して値を突っ込んでみるも、うまくいかず。。
Befor the mapper xml files are parsed?
mybatis-user.963551.n3.nabble.com
Jorge, make sure that config.getVariables().put() is called befor the mapper xml files are parsed.
I do not know if this behaviour is intentional but varable replacement work for mybatis-config.xml and also form mappers but just during loading time.
どうもmapper.xmlをparseする前とか、Config(ファイル)を読む前に突っ込めばうまくいく?
Spring-mybatisだとどこでやってるんだろう。。
MybatisAutoConfiguration?
たぶんSqlSessionFactoryの生成あたりでやってそうな雰囲気はある。
けど既存に影響を与えない形でうまくいく方法が浮かばない。。ので現時点では諦めることにした。