Skip to content

Commit

Permalink
Polish apache#4690 : AnnotatedBeanDefinitionRegistryUtils#registerBea…
Browse files Browse the repository at this point in the history
…ns can't remove the duplicated bean definitions
  • Loading branch information
mercyblitz committed Aug 21, 2019
1 parent e819462 commit 46999e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

import static java.lang.String.format;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -95,7 +95,7 @@ public static void registerBeans(BeanDefinitionRegistry registry, Class<?>... an
return;
}

List<Class<?>> classesToRegister = new LinkedList<>(asList(annotatedClasses));
Set<Class<?>> classesToRegister = new LinkedHashSet<>(asList(annotatedClasses));

// Remove all annotated-classes that have been registered
Iterator<Class<?>> iterator = classesToRegister.iterator();
Expand All @@ -115,5 +115,7 @@ public static void registerBeans(BeanDefinitionRegistry registry, Class<?>... an

reader.register(classesToRegister.toArray(new Class[0]));

// clear
classesToRegister.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Service;
Expand All @@ -36,6 +37,11 @@ public class AnnotatedBeanDefinitionRegistryUtilsTest {

private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

@BeforeEach
public void init() {
context.setAllowBeanDefinitionOverriding(false);
}

@AfterEach
public void destroy() {
context.close();
Expand Down

0 comments on commit 46999e1

Please sign in to comment.