- 👋 Hi, I’m Jarvis
easybest / spring-boot-starter-data-mybatis Goto Github PK
View Code? Open in Web Editor NEWStarter for using Spring Data MyBatis
License: Apache License 2.0
Starter for using Spring Data MyBatis
License: Apache License 2.0
Hello,
Does it support Spring Boot 2?
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.
Add the configLocation property to MybatisProperties.java
private String configLocation;
...
public String getConfigLocation() {
return configLocation;
}
public void setConfigLocation(String configLocation) {
this.configLocation = configLocation;
}
Add configLocation part to MybatisRepositoriesAutoConfigureRegistrar.java
@OverRide
public void setEnvironment(Environment environment) {
...
properties.setConfigLocation(environment.getProperty(MybatisProperties.PREFIX + ".config-location", String.class));
...
}
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()));
}
...
}
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.
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:
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
我看到issues中应该已经解决了与官方starter冲突的问题。
看了一下配置项,比官方的少,不能完全替代,而且用这个也无法很好的从旧项目过度过来。
比如官方的org.apache.ibatis.annotations.Mapper注解应该没在配置中支持,以及一些常用的setting项无法直接配置。
而且两个starter又存在同功能的配置,有点纠结。
我觉得要么应该跟官方的配合,只作为一个补充的配置。
要么在功能上可以完全替代官方的。
但我觉得第一种会更好点,除非官方的配置跟框架中的功能存在冲突。
@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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.