Skip to content

Support dependency injection in custom type handlers #493

@TranNgocKhoa

Description

@TranNgocKhoa

I know there is already an issue at #218 and solution is:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- .... -->
        <property name="typeHandlers">
          <array>
            <bean class="com.example.YurCustomTypeHandler">
              <property name="aProperty" ref="aBean"/>
            </bean>
          </array>
        </property>
    </bean>

But I think bellow is better because now is 2020 and we should use Java Configuration.

public class JsonObjectArrayHandler extends BaseTypeHandler<List<Gallery>> {
    private final ObjectMapper objectMapper;

    public JsonObjectArrayHandler(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

And then in application.yml of Spring Boot application:

mybatis:
  type-handlers-package: com.example.handler

Please add support for this.
Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions