Error with interface TypeHandler for enum with interface
See original GitHub issueHi, I think I found an issue for a rather specific case.
I’m not sure if this issue belongs to this repo, Spring integration, or MyBatis core.
I put it here for now, because the demo is using TypeHandler
’s component scanning.
When trying to map an enum with an interface using the interface’s TypeHandler
Spring bean, there are cases which throws the following exception:
...
Caused by: org.apache.ibatis.type.TypeException: Unable to find a usable constructor for class com.example.demo.mybatis.TheInterfaceTypeHandler
at org.apache.ibatis.type.TypeHandlerRegistry.getInstance(TypeHandlerRegistry.java:457) ~[mybatis-3.5.5.jar:3.5.5]
at org.apache.ibatis.type.TypeHandlerRegistry.getJdbcHandlerMapForEnumInterfaces(TypeHandlerRegistry.java:286) ~[mybatis-3.5.5.jar:3.5.5]
at org.apache.ibatis.type.TypeHandlerRegistry.getJdbcHandlerMap(TypeHandlerRegistry.java:262) ~[mybatis-3.5.5.jar:3.5.5]
at org.apache.ibatis.type.TypeHandlerRegistry.getTypeHandler(TypeHandlerRegistry.java:237) ~[mybatis-3.5.5.jar:3.5.5]
...
Caused by: java.lang.NoSuchMethodException: com.example.demo.mybatis.TheInterfaceTypeHandler.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_265]
at java.lang.Class.getConstructor(Class.java:1825) ~[na:1.8.0_265]
As I understand it, MyBatis is trying to instantiate a new TypeHandler
instead of using the one registered as Spring bean, which it failed because the type handler class requires another Spring bean (therefore no no-arg constructor).
Here’s the sample code for demonstrating the case: https://github.com/KniveX/bugreport-springboot-mybatis-200816
- Java 8 (OpenJDK 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
- Spring Boot (2.3.3.RELEASE)
- mybatis-spring-boot-starter (2.1.3)
Thank you, and I apologize if my english is not clear.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
I think you don’t need to use the spring bean in this case. I’ve modified as follow, it work fine. WDYT?
Your solution works great! I guess this issue can be safely closed.
Thanks a lot for your help @kazuki43zoo. Cheers