Git Product home page Git Product logo

spring-boot-starter-data-mybatis's Introduction

  • 👋 Hi, I’m Jarvis

spring-boot-starter-data-mybatis's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-boot-starter-data-mybatis's Issues

Add config location

  • This content is translated into Google Translator, so the sentence is not smooth. Please consider it.

In mybatis project, I used "mybatis.config-location" property to specify xml for mybatis environment setting.
I can not specify the config-location attribute to apply spring-boot-starter-data-mybatis to this project.
I do not know if you've blocked it for some reason, but once I try to apply it to an existing project, it is difficult to specify typeAlias, typeHandlers, and so on.
So I added config to 1.0.15.release version source and it seems to work well.
I would like to share this information with you.

  1. Add the configLocation property to MybatisProperties.java

    private String configLocation;
    ...
    public String getConfigLocation() {
    return configLocation;
    }

    public void setConfigLocation(String configLocation) {
    this.configLocation = configLocation;
    }

  2. Add configLocation part to MybatisRepositoriesAutoConfigureRegistrar.java

    @OverRide
    public void setEnvironment(Environment environment) {
    ...
    properties.setConfigLocation(environment.getProperty(MybatisProperties.PREFIX + ".config-location", String.class));
    ...
    }

  3. Specify the configLocation in the method that creates the SqlSessionFactoryBean bean in MybatisRepositoriesAutoConfiguration.java.

    @bean
    @ConditionalOnMissingBean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws Exception {
    ...

     if (!StringUtils.isEmpty(properties.getConfigLocation())) {
         factoryBean.setConfigLocation(ResourcePatternUtils.getResourcePatternResolver(this.resourceLoader).getResource(properties.getConfigLocation()));
     }
     ...
    

    }

Conflict with standard mybatis starter

when i try to use both starters spring-boot-starter-data-mybatis and mybatis-spring-boot-starter, i have an exception that two SqlSessionTemplate beans were created.

[Question] How to preload mapper before xml rendering happen

We are trying to add a SELECT_CONDITION_INNER sql fragment.
I have tried to create it in my mapper but it complain that a default one as already been added:

https://github.com/hatunet/spring-data-mybatis/blob/adeae420c8f09a88c0c7aed5676ccc1401954c33/src/main/java/org/springframework/data/mybatis/repository/support/MybatisSimpleRepositoryMapperGenerator.java#L125

I have created a xml to be injected in the configuration :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.domain.api.core.domain.Role">

  <sql id="SELECT_CONDITION_INNER">
    <if test="_condition.linkUserId != null">
      and role.id in
      (select role_id from role_user where user_id = #{_condition.linkUserId,jdbcType=NUMERIC})
    </if>
  </sql>

</mapper>

spring-boot-starter-data-mybatis is responsible for AutoConfiguring beforemappers but my AutoConfiguration reports says ConditionalOnMissingBean is failing beacuse of MybatisRepositoryConfigExtension

MybatisRepositoriesAutoConfiguration:
  Did not match:
     - @ConditionalOnMissingBean (types: org.springframework.data.mybatis.repository.config.MybatisRepositoryConfigExtension; SearchStrategy: all) found bean 'org.springframework.data.mybatis.repository.config.MybatisRepositoryConfigExtension#0' (OnBeanCondition)
  Matched:
     - @ConditionalOnClass found required classes 'org.springframework.data.mybatis.repository.support.MybatisRepository', 'org.apache.ibatis.session.SqlSessionFactory'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
     - @ConditionalOnProperty (spring.data.mybatis.repositories.enabled=true) matched (OnPropertyCondition)

Do you know how I could get my before mapper loaded ?

Version : 1.0.17

与官方mybatis-spring-boot-starter共用

我看到issues中应该已经解决了与官方starter冲突的问题。

看了一下配置项,比官方的少,不能完全替代,而且用这个也无法很好的从旧项目过度过来。
比如官方的org.apache.ibatis.annotations.Mapper注解应该没在配置中支持,以及一些常用的setting项无法直接配置。
而且两个starter又存在同功能的配置,有点纠结。

我觉得要么应该跟官方的配合,只作为一个补充的配置。
要么在功能上可以完全替代官方的。
但我觉得第一种会更好点,除非官方的配置跟框架中的功能存在冲突。

@EnableMybatisRepositories doesn't work with beforemappers

@EnableMybatisRepositories is required if you want to create more than one transactionManager.

@EnableMybatisRepositories(
        transactionManagerRef = "userManagementTransactionManager",
        sqlSessionFactoryRef = "userManagementSqlSessionFactory",
        value = "com.domain.api.userManagement.repository",
        mapperLocations = {
                "classpath*:/mappers/userManagement/*Mapper.xml"
        }
)

Using @EnableMybatisRepositories also disable MybatisRepositoriesAutoConfiguration which configure beforemapper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.