Reputation: 7795
In MyBatis documentation I see only example of adding mappers by exact name.
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
<mapper resource="org/mybatis/builder/BlogMapper.xml"/>
<mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>
Specifying each mapper name looks like a redundant verbosity, and I am wondering if there is a way to do the same with wildcards like this:
<mappers>
<mapper resource="org/mybatis/builder/*Mapper.xml"/>
</mappers>
In mybatis-spring-boot-starter
they have a property mybatis.mapper-locations
that could be used as follows:
mybatis.mapper-locations=classpath:org/mybatis/builder/*Mapper.xml
The only disadvantage is that it involves tons code and Spring autoconfiguring magic under the hood.
Is it possible to add wildcarded mappers path into config xml using MyBatis itself (without Spring dependencies)?
or is there a reason why this useful feature is not available?
Upvotes: 0
Views: 931
Reputation: 991
From that same documentation page - you can register a package and all interfaces in the package will be registered. This is far less verbose than registering mappers individually:
<!-- Register all interfaces in a package as mappers -->
<mappers>
<package name="org.mybatis.builder"/>
</mappers>
Upvotes: 1