mybatis is not able to find typehandlers

19 views
Skip to first unread message

Marvin Berger

unread,
Feb 10, 2020, 5:18:32 AM2/10/20
to mybatis-user
Hey,

I am currently creating my first object with spring boot and mybatis, so please be patient with me, if the mistake is obvious.
When I start the application, I always get a ClassNotFoundException for the Class TrimmedStringTypeHandler. 
In my mapper xml file I wrote something like this:
        <result property="bezeichnung" column="VP_POS_BEZ" typeHandler="TrimmedStringTypeHandler" />
The handler looks like this:

package de.firma.iservice.bvs.core.typehandler;


public class TrimmedStringTypeHandler extends BaseTypeHandler<String> {...}

Finally, my application.yml looks like this:

spring.datasource.maximum-pool-size: 10

mybatis:
  type-handlers-package: de.firma.iservice.bvs.core.typehandler
  type-aliases-package: de.firma.iservice.bvs.core.models.*
  mapper-locations: /mapper/*Mapper.xml

Am I missing something?

What really confuses me, although it is kind of a workaround: 
If I add the package of the typehandler to the type-aliases-package property, everything works flawless. But this does not seem right. Is it?

Iwao AVE!

unread,
Feb 11, 2020, 11:20:36 PM2/11/20
to mybatis-user

Hello Marvin,

type-handlers-package is used to register type handlers globally.
So, this is the setting you use when you want to override the built-in StringTypeHandler.
You may need to add @MappedTypes(String.class) to the type handler.
As global type handlers are used implicitly, you don't need to specify typeHandler in <result />.

Now, if you want to use TrimmedStringTypeHandler only for particular properties, remove type-handlers-package from the config and specify typeHandler="de.firma.iservice.bvs.core.typehandler.TrimmedStringTypeHandler" in each <result />.
To use short names (i.e. typeHandler="TrimmedStringTypeHandler"), you need to register the aliases. e.g.

type-aliases-package: de.firma.iservice.bvs.core.models,de.firma.iservice.bvs.core.typehandler

(* is unnecessary)

Please let me know if you have any further questions.

Regards,
Iwao



--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/748786d6-90b8-497c-acec-62f61ca897cb%40googlegroups.com.

Marvin Berger

unread,
Feb 12, 2020, 2:17:39 AM2/12/20
to mybatis-user
Thank you so much, seems like I just had a misunderstanding and stumbled across the correct configuration. 
Reply all
Reply to author
Forward
0 new messages