Closed
Description
Since 2.0.1, the SqlSessionFactoryBean
cannot scan TypeHandler
that pass Class<?>
to constructor as follow:
@MappedTypes(JSONObject.class)
public class JSONObjectTypeHandler extends BaseTypeHandler<JSONObject> {
public JSONObjectTypeHandler(Class<JSONObject> type) {
super(type);
}
// ...
}
The cause of this behavior was created by #359. In this changes, it scan only TypeHandler
that can create instance using default constructor.
We should be scan TypeHandler
that create instance using constructor that pass Class or default constructor.
Related Issues
- Cannot scan TypeHandler that pass Class<?> to constructor since 2.0.1 spring-boot-starter#370
- Allow to specify a wildcard at typeAliasesPackage and typeHandlersPackage #359
Workaround
You can specify a custom type handler using typeHandlers
property as follow:
- Java Configuration
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setTypeHanlders(new JSONObjectTypeHandler(JSONObject.class));
// ...
- XML Configuration
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="typeHanlders">
<array>
<bean class="com.example.typehandler.JSONObjectTypeHandler">
<constructor-arg value="com.example.json.JSONObject" />
</bean>
</array>
</bean>
</property>
<!-- ... -->
</bean>