mybatis TypeHandler 注入spring的依赖

解决方法

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

在mybatis想通过写一个自定义的handler实现业务功能,该handler默认创建的时候,是不在spring的管理范围里的,所以你在handler用@Autowired注入,是会报npe。需要通过上面的方式,就可以解决了。

你可能感兴趣的:(mybatis)