Skip to content

Cannot scan TypeHandler that pass Class<?> to constructor #394

Closed
@kazuki43zoo

Description

@kazuki43zoo

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

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>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions