spring-bootmybatisspring-mybatis

MyBatis: Autoscan for type aliases


I have a MyBatis mapper.xml file with this entry :

<select id="findAll"
            resultType="User">
...
</select>

... the "User" class is in this package :

com.company.model.User

... and in application.properties I have this entry :

mybatis.type-aliases-package = com.company.model

And everything works fine.

After refactoring and moving some classes into sub-packages MyBatis can't find them anymore during autoscan.

Package structure is now like this :

com.company.entity.users.User
com.company.entity.departments.Department
com.company.entity.students.Student

I've tried (among many other variations: with '/' instead of '.', without 'classpath:', etc) :

mybatis.type-aliases-package = classpath:com.company.entity.*

but couldn't make it work.

How can I tell MyBatis to scan under all sub-packages of package "com.company.entity"?


Solution

  • According Mybatis configuration you can use delimiters to separate the packages that you need. These are the delimiters:

    ",; \t\n"

    Then you can set by following way:

    mybatis.type-aliases-package = com.company.entity.users,com.company.entity.departments,com.company.entity.students