Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kazuki43zoo opened this issue Jul 20, 2019 · 0 comments · Fixed by #395
Closed

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

kazuki43zoo opened this issue Jul 20, 2019 · 0 comments · Fixed by #395
Assignees
Labels
Milestone

Comments

@kazuki43zoo
Copy link
Member

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>
@kazuki43zoo kazuki43zoo added this to the 1.3.3 milestone Jul 20, 2019
@kazuki43zoo kazuki43zoo self-assigned this Jul 20, 2019
@kazuki43zoo kazuki43zoo modified the milestones: 1.3.3, 2.0.3 Jul 20, 2019
kazuki43zoo added a commit to kazuki43zoo/spring that referenced this issue Jul 20, 2019
kazuki43zoo added a commit to kazuki43zoo/spring that referenced this issue Jul 20, 2019
kazuki43zoo added a commit that referenced this issue Jul 20, 2019
Allow to scan TypeHandler that pass Class<?> to constructor
pulllock pushed a commit to pulllock/mybatis-spring that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-spring that referenced this issue Oct 19, 2023
Allow to scan TypeHandler that pass Class<?> to constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant