mybatis is not able to find typehandlers

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

mybatis is not able to find typehandlers

Marvin Berger
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/748786d6-90b8-497c-acec-62f61ca897cb%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: mybatis is not able to find typehandlers

Iwao AVE!

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



On Mon, Feb 10, 2020 at 7:18 PM Marvin Berger <[hidden email]> wrote:
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/748786d6-90b8-497c-acec-62f61ca897cb%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CA%2Buep2Tu4XTTe85QuzSMjgKUcSJuUrD_2nPEpvNm70aEdPnm6Q%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: mybatis is not able to find typehandlers

Marvin Berger
In reply to this post by Marvin Berger
Thank you so much, seems like I just had a misunderstanding and stumbled across the correct configuration. 

Am Montag, 10. Februar 2020 11:18:32 UTC+1 schrieb Marvin Berger:
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/5e5e95ab-a8dd-4eed-90e3-4f545b2265d0%40googlegroups.com.