mybatis: Using mapper interfaces with XML config for global parameters

ripper234 picture ripper234 · Nov 24, 2010 · Viewed 16.1k times · Source

I like the XML notation for specifying global parameters such as connection strings. I also like Mapper annotations. When I try to combine the two, I get this exception.

Is there a way to combine the two? I would like to use an XML file for the global configurations, but have mybatis take Mapper interfaces into account.

The problem is that SqlSessionFactoryBuilder().build() takes either a Reader (which I want to use to pass the XML config), or a Configuration object (which I see has the addMappers() method that can help me) - but I don't understand how to combine the two.

Answer

Atilio Ranzuglia picture Atilio Ranzuglia · Jan 6, 2011

factory.getConfiguration().addMapper(...);