Skip to content

Commit

Permalink
Corrected to set bean class instead of bean class name to factoryBean…
Browse files Browse the repository at this point in the history
…ObjectType of BeanDefinition attribute.

Fixes mybatisgh-855
* Related with mybatisgh-494
* Related with spring-projects/spring-framework#29799
  • Loading branch information
kazuki43zoo committed Oct 23, 2023
1 parent 4275397 commit a781e86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
// but, the actual class of the bean is MapperFactoryBean
definition.getConstructorArgumentValues().addGenericArgumentValue(beanClassName); // issue #59
try {
Class<?> beanClass = Resources.classForName(beanClassName);
// Attribute for MockitoPostProcessor
// https://github.com/mybatis/spring-boot-starter/issues/475
definition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, beanClass);
// for spring-native
definition.getPropertyValues().add("mapperInterface", Resources.classForName(beanClassName));
definition.getPropertyValues().add("mapperInterface", beanClass);
} catch (ClassNotFoundException ignore) {
// ignore
}
Expand All @@ -272,10 +276,6 @@ private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {

definition.getPropertyValues().add("addToConfig", this.addToConfig);

// Attribute for MockitoPostProcessor
// https://github.com/mybatis/spring-boot-starter/issues/475
definition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, beanClassName);

boolean explicitFactoryUsed = false;
if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) {
definition.getPropertyValues().add("sqlSessionFactory",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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 Down Expand Up @@ -399,7 +399,7 @@ void testMapperBeanAttribute() {
startContext();

assertThat(applicationContext.getBeanDefinition("annotatedMapper")
.getAttribute(ClassPathMapperScanner.FACTORY_BEAN_OBJECT_TYPE)).isEqualTo(AnnotatedMapper.class.getName());
.getAttribute(ClassPathMapperScanner.FACTORY_BEAN_OBJECT_TYPE)).isEqualTo(AnnotatedMapper.class);
}

private void setupSqlSessionFactory(String name) {
Expand Down

0 comments on commit a781e86

Please sign in to comment.