Polishing (backported from main)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,6 +25,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.springframework.beans.SimpleTypeConverter;
|
import org.springframework.beans.SimpleTypeConverter;
|
||||||
import org.springframework.beans.TypeConverter;
|
import org.springframework.beans.TypeConverter;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||||
@@ -240,10 +241,11 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targetAnnotation == null) {
|
if (targetAnnotation == null) {
|
||||||
|
BeanFactory beanFactory = getBeanFactory();
|
||||||
// Look for matching annotation on the target class
|
// Look for matching annotation on the target class
|
||||||
if (getBeanFactory() != null) {
|
if (beanFactory != null) {
|
||||||
try {
|
try {
|
||||||
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
|
Class<?> beanType = beanFactory.getType(bdHolder.getBeanName());
|
||||||
if (beanType != null) {
|
if (beanType != null) {
|
||||||
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
|
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -547,7 +547,8 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
|
|||||||
* @see DefaultNamespaceHandlerResolver#DefaultNamespaceHandlerResolver(ClassLoader)
|
* @see DefaultNamespaceHandlerResolver#DefaultNamespaceHandlerResolver(ClassLoader)
|
||||||
*/
|
*/
|
||||||
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
|
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
|
||||||
ClassLoader cl = (getResourceLoader() != null ? getResourceLoader().getClassLoader() : getBeanClassLoader());
|
ResourceLoader resourceLoader = getResourceLoader();
|
||||||
|
ClassLoader cl = (resourceLoader != null ? resourceLoader.getClassLoader() : getBeanClassLoader());
|
||||||
return new DefaultNamespaceHandlerResolver(cl);
|
return new DefaultNamespaceHandlerResolver(cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -436,7 +436,6 @@ class DefaultListableBeanFactoryTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void empty() {
|
void empty() {
|
||||||
ListableBeanFactory lbf = new DefaultListableBeanFactory();
|
|
||||||
assertThat(lbf.getBeanDefinitionNames() != null).as("No beans defined --> array != null").isTrue();
|
assertThat(lbf.getBeanDefinitionNames() != null).as("No beans defined --> array != null").isTrue();
|
||||||
assertThat(lbf.getBeanDefinitionNames().length == 0).as("No beans defined after no arg constructor").isTrue();
|
assertThat(lbf.getBeanDefinitionNames().length == 0).as("No beans defined after no arg constructor").isTrue();
|
||||||
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after no arg constructor").isTrue();
|
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after no arg constructor").isTrue();
|
||||||
@@ -778,21 +777,6 @@ class DefaultListableBeanFactoryTests {
|
|||||||
assertThat(factory.getType("child")).isEqualTo(DerivedTestBean.class);
|
assertThat(factory.getType("child")).isEqualTo(DerivedTestBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void nameAlreadyBound() {
|
|
||||||
Properties p = new Properties();
|
|
||||||
p.setProperty("kerry.(class)", TestBean.class.getName());
|
|
||||||
p.setProperty("kerry.age", "35");
|
|
||||||
registerBeanDefinitions(p);
|
|
||||||
try {
|
|
||||||
registerBeanDefinitions(p);
|
|
||||||
}
|
|
||||||
catch (BeanDefinitionStoreException ex) {
|
|
||||||
assertThat(ex.getBeanName()).isEqualTo("kerry");
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void singleTestBean(ListableBeanFactory lbf) {
|
private void singleTestBean(ListableBeanFactory lbf) {
|
||||||
assertThat(lbf.getBeanDefinitionCount() == 1).as("1 beans defined").isTrue();
|
assertThat(lbf.getBeanDefinitionCount() == 1).as("1 beans defined").isTrue();
|
||||||
String[] names = lbf.getBeanDefinitionNames();
|
String[] names = lbf.getBeanDefinitionNames();
|
||||||
|
|||||||
Reference in New Issue
Block a user