Is it possible to have both the XML + Annotation based configuration for MyBatis in an application.
The reason that I am asking this is because, in my application I am using the Annotation based approach.
But in one of the scenarios , I require to use an IN clause, which can be built using the
<foreach></foreach>
based XML configuration.
However , when I start my application , it does not seem to recognize my Annotation based mappers and gives me a Type interface is not known to the MapperRegistry exception
Therefore I would like to know whether is it possible to have both the XML + Annotation based configuration for MyBatis in an application.
Please suggest.
Its possible to have both XML + Annotation based configuration
For xml based configuration:
Start with your spring context file.In your context file add following lines
your mybatis-config.xml should be something like this:
and your userMapper.xml in src/com/yourcomp/domain/ might be something like this
now in your DAO layer you might have class like follows:
Now For using annotation based configuration add the followings:
You might have an interface like follows:
now add the followings to your context file:
Hope this helps 🙂