Skip to content

Commit 8b22af6

Browse files
Change logger to slf4j
1 parent 65cc15a commit 8b22af6

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<spring.version>7.0.1</spring.version>
118118
<spring-boot.version>4.0.0</spring-boot.version>
119119
<spring-batch.version>5.2.4</spring-batch.version>
120+
<slf4j.version>2.0.17</slf4j.version>
120121
<module.name>org.mybatis.spring</module.name>
121122

122123
<junit.version>6.0.1</junit.version>
@@ -165,6 +166,13 @@
165166
<optional>true</optional>
166167
</dependency>
167168

169+
<dependency>
170+
<groupId>org.slf4j</groupId>
171+
<artifactId>slf4j-api</artifactId>
172+
<version>${slf4j.version}</version>
173+
<scope>provided</scope>
174+
</dependency>
175+
168176
<!-- Test dependencies -->
169177

170178
<dependency>
@@ -246,7 +254,7 @@
246254
<dependency>
247255
<groupId>org.slf4j</groupId>
248256
<artifactId>slf4j-simple</artifactId>
249-
<version>2.0.17</version>
257+
<version>${slf4j.version}</version>
250258
<scope>test</scope>
251259
</dependency>
252260

src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,9 @@
2323

2424
import org.apache.ibatis.io.Resources;
2525
import org.apache.ibatis.session.SqlSessionFactory;
26-
import org.mybatis.logging.Logger;
27-
import org.mybatis.logging.LoggerFactory;
2826
import org.mybatis.spring.SqlSessionTemplate;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2929
import org.springframework.aop.scope.ScopedProxyFactoryBean;
3030
import org.springframework.aop.scope.ScopedProxyUtils;
3131
import org.springframework.aot.AotDetector;
@@ -256,8 +256,8 @@ public Set<BeanDefinitionHolder> doScan(String... basePackages) {
256256

257257
if (beanDefinitions.isEmpty()) {
258258
if (printWarnLogIfNotFoundMappers) {
259-
LOGGER.warn(() -> "No MyBatis mapper was found in '" + Arrays.toString(basePackages)
260-
+ "' package. Please check your configuration.");
259+
LOGGER.warn("No MyBatis mapper was found in '{}' package. Please check your configuration.",
260+
Arrays.toString(basePackages));
261261
}
262262
} else {
263263
processBeanDefinitions(beanDefinitions);
@@ -280,8 +280,8 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
280280
scopedProxy = true;
281281
}
282282
var beanClassName = definition.getBeanClassName();
283-
LOGGER.debug(() -> "Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + beanClassName
284-
+ "' mapperInterface");
283+
LOGGER.debug("Creating MapperFactoryBean with name '{}' and '{}' mapperInterface", holder.getBeanName(),
284+
beanClassName);
285285

286286
// the mapper interface is the original class of the bean
287287
// but, the actual class of the bean is MapperFactoryBean
@@ -314,22 +314,22 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
314314
if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) {
315315
if (explicitFactoryUsed) {
316316
LOGGER.warn(
317-
() -> "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
317+
"Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
318318
}
319319
definition.getPropertyValues().add("sqlSessionTemplate",
320320
new RuntimeBeanReference(this.sqlSessionTemplateBeanName));
321321
explicitFactoryUsed = true;
322322
} else if (this.sqlSessionTemplate != null) {
323323
if (explicitFactoryUsed) {
324324
LOGGER.warn(
325-
() -> "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
325+
"Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
326326
}
327327
definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate);
328328
explicitFactoryUsed = true;
329329
}
330330

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

@@ -364,8 +364,9 @@ protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition)
364364
if (super.checkCandidate(beanName, beanDefinition)) {
365365
return true;
366366
}
367-
LOGGER.warn(() -> "Skipping MapperFactoryBean with name '" + beanName + "' and '"
368-
+ beanDefinition.getBeanClassName() + "' mapperInterface" + ". Bean already defined with the same name!");
367+
LOGGER.warn(
368+
"Skipping MapperFactoryBean with name '{}' and '{}' mapperInterface. Bean already defined with the same name!",
369+
beanName, beanDefinition.getBeanClassName());
369370
return false;
370371
}
371372

0 commit comments

Comments
 (0)