Does mybatis support multiple configuration file?

105 views
Skip to first unread message

George

unread,
Oct 26, 2011, 11:28:33 AM10/26/11
to mybati...@googlegroups.com
I am an user of ibatis and i found that when my project includes more than two modules, the configuration file becomes very hard to maintain. I mean you can add many mapper files that belong to your modules to the ibatis configuration file, and all of the modules share the same settings, environments, type-alias etc, the question is what if some settings should be just for module A, so they are meaningless for other modules? The best thing i got is ibatis should support multiple configuration file, and let the module maintain the configuration by itself and the project just load the sub-configuration files as it loads the mapper files?

Is this possible with mybatis?

Best,

George

Guy

unread,
Oct 28, 2011, 12:51:04 AM10/28/11
to mybatis-user
I don't know your runtime environment (Spring Guice with injection or
simple Java) but if the latter, you specify which configuration file
you want to load by doing something like this:

Reader reader = Resources.getResourceAsReader("iBatisConfig.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

You can do this as many times as you'd like within a single program,
so you can load multiple configurations. You then create your mappers
from the desired SqlSessionFactory or SqlSessionManager.

Is this not what you mean?

George Cao

unread,
Oct 30, 2011, 9:15:43 AM10/30/11
to mybati...@googlegroups.com

Thanks a lot. I do not use spring in my project,and your example just inspired me that i can use different configuration file directly.

Reply all
Reply to author
Forward
0 new messages