Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<spring.version>7.0.1</spring.version>
<spring-boot.version>4.0.0</spring-boot.version>
<spring-batch.version>5.2.4</spring-batch.version>
<slf4j.version>2.0.17</slf4j.version>
<module.name>org.mybatis.spring</module.name>

<junit.version>6.0.1</junit.version>
Expand Down Expand Up @@ -165,6 +166,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->

<dependency>
Expand Down Expand Up @@ -246,7 +254,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2024 the original author or authors.
* Copyright 2010-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,9 +23,9 @@

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.scope.ScopedProxyFactoryBean;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.aot.AotDetector;
Expand Down Expand Up @@ -256,8 +256,8 @@ public Set<BeanDefinitionHolder> doScan(String... basePackages) {

if (beanDefinitions.isEmpty()) {
if (printWarnLogIfNotFoundMappers) {
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
+ "' package. Please check your configuration.");
LOGGER.warn("No MyBatis mapper was found in '{}' package. Please check your configuration.",
Arrays.toString(basePackages));
}
} else {
processBeanDefinitions(beanDefinitions);
Expand All @@ -280,8 +280,8 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
scopedProxy = true;
}
var beanClassName = definition.getBeanClassName();
LOGGER.debug(() -> "Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + beanClassName
+ "' mapperInterface");
LOGGER.debug("Creating MapperFactoryBean with name '{}' and '{}' mapperInterface", holder.getBeanName(),
beanClassName);

// the mapper interface is the original class of the bean
// but, the actual class of the bean is MapperFactoryBean
Expand Down Expand Up @@ -314,22 +314,22 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) {
if (explicitFactoryUsed) {
LOGGER.warn(
() -> "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
"Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
}
definition.getPropertyValues().add("sqlSessionTemplate",
new RuntimeBeanReference(this.sqlSessionTemplateBeanName));
explicitFactoryUsed = true;
} else if (this.sqlSessionTemplate != null) {
if (explicitFactoryUsed) {
LOGGER.warn(
() -> "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
"Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
}
definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate);
explicitFactoryUsed = true;
}

if (!explicitFactoryUsed) {
LOGGER.debug(() -> "Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'.");
LOGGER.debug("Enabling autowire by type for MapperFactoryBean with name '{}'.", holder.getBeanName());
definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
}

Expand Down Expand Up @@ -364,8 +364,9 @@ protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition)
if (super.checkCandidate(beanName, beanDefinition)) {
return true;
}
LOGGER.warn(() -> "Skipping MapperFactoryBean with name '" + beanName + "' and '"
+ beanDefinition.getBeanClassName() + "' mapperInterface" + ". Bean already defined with the same name!");
LOGGER.warn(
"Skipping MapperFactoryBean with name '{}' and '{}' mapperInterface. Bean already defined with the same name!",
beanName, beanDefinition.getBeanClassName());
return false;
}

Expand Down