Skip to content

Commit a8b747c

Browse files
committed
Polishing
1 parent 490b78a commit a8b747c

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -78,7 +78,7 @@ public BeanDefinitionStoreException(@Nullable String resourceDescription, String
7878
/**
7979
* Create a new BeanDefinitionStoreException.
8080
* @param resourceDescription description of the resource that the bean definition came from
81-
* @param beanName the name of the bean requested
81+
* @param beanName the name of the bean
8282
* @param msg the detail message (appended to an introductory message that indicates
8383
* the resource and the name of the bean)
8484
*/
@@ -89,29 +89,31 @@ public BeanDefinitionStoreException(@Nullable String resourceDescription, String
8989
/**
9090
* Create a new BeanDefinitionStoreException.
9191
* @param resourceDescription description of the resource that the bean definition came from
92-
* @param beanName the name of the bean requested
92+
* @param beanName the name of the bean
9393
* @param msg the detail message (appended to an introductory message that indicates
9494
* the resource and the name of the bean)
9595
* @param cause the root cause (may be {@code null})
9696
*/
97-
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
98-
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
97+
public BeanDefinitionStoreException(
98+
@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
99+
100+
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg,
101+
cause);
99102
this.resourceDescription = resourceDescription;
100103
this.beanName = beanName;
101104
}
102105

103106

104107
/**
105-
* Return the description of the resource that the bean
106-
* definition came from, if any.
108+
* Return the description of the resource that the bean definition came from, if available.
107109
*/
108110
@Nullable
109111
public String getResourceDescription() {
110112
return this.resourceDescription;
111113
}
112114

113115
/**
114-
* Return the name of the bean requested, if any.
116+
* Return the name of the bean, if available.
115117
*/
116118
@Nullable
117119
public String getBeanName() {

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionRegistry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -55,6 +55,7 @@ public interface BeanDefinitionRegistry extends AliasRegistry {
5555
* @throws BeanDefinitionStoreException if the BeanDefinition is invalid
5656
* or if there is already a BeanDefinition for the specified bean name
5757
* (and we are not allowed to override it)
58+
* @see GenericBeanDefinition
5859
* @see RootBeanDefinition
5960
* @see ChildBeanDefinition
6061
*/

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -802,34 +802,32 @@ public void registerBeanDefinition(String beanName, BeanDefinition beanDefinitio
802802
}
803803
}
804804

805-
BeanDefinition oldBeanDefinition;
806-
807-
oldBeanDefinition = this.beanDefinitionMap.get(beanName);
808-
if (oldBeanDefinition != null) {
805+
BeanDefinition existingDefinition = this.beanDefinitionMap.get(beanName);
806+
if (existingDefinition != null) {
809807
if (!isAllowBeanDefinitionOverriding()) {
810808
throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName,
811809
"Cannot register bean definition [" + beanDefinition + "] for bean '" + beanName +
812-
"': There is already [" + oldBeanDefinition + "] bound.");
810+
"': There is already [" + existingDefinition + "] bound.");
813811
}
814-
else if (oldBeanDefinition.getRole() < beanDefinition.getRole()) {
812+
else if (existingDefinition.getRole() < beanDefinition.getRole()) {
815813
// e.g. was ROLE_APPLICATION, now overriding with ROLE_SUPPORT or ROLE_INFRASTRUCTURE
816814
if (logger.isWarnEnabled()) {
817815
logger.warn("Overriding user-defined bean definition for bean '" + beanName +
818816
"' with a framework-generated bean definition: replacing [" +
819-
oldBeanDefinition + "] with [" + beanDefinition + "]");
817+
existingDefinition + "] with [" + beanDefinition + "]");
820818
}
821819
}
822-
else if (!beanDefinition.equals(oldBeanDefinition)) {
820+
else if (!beanDefinition.equals(existingDefinition)) {
823821
if (logger.isInfoEnabled()) {
824822
logger.info("Overriding bean definition for bean '" + beanName +
825-
"' with a different definition: replacing [" + oldBeanDefinition +
823+
"' with a different definition: replacing [" + existingDefinition +
826824
"] with [" + beanDefinition + "]");
827825
}
828826
}
829827
else {
830828
if (logger.isDebugEnabled()) {
831829
logger.debug("Overriding bean definition for bean '" + beanName +
832-
"' with an equivalent definition: replacing [" + oldBeanDefinition +
830+
"' with an equivalent definition: replacing [" + existingDefinition +
833831
"] with [" + beanDefinition + "]");
834832
}
835833
}
@@ -860,7 +858,7 @@ else if (!beanDefinition.equals(oldBeanDefinition)) {
860858
this.frozenBeanDefinitionNames = null;
861859
}
862860

863-
if (oldBeanDefinition != null || containsSingleton(beanName)) {
861+
if (existingDefinition != null || containsSingleton(beanName)) {
864862
resetBeanDefinition(beanName);
865863
}
866864
}

spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanAnnotationAttributePropagationTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -18,6 +18,7 @@
1818

1919
import org.junit.Test;
2020

21+
import org.springframework.beans.factory.annotation.Autowire;
2122
import org.springframework.beans.factory.config.BeanDefinition;
2223
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2324
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -41,9 +42,20 @@
4142
* correctly into the resulting BeanDefinition
4243
*
4344
* @author Chris Beams
45+
* @author Juergen Hoeller
4446
*/
4547
public class BeanAnnotationAttributePropagationTests {
4648

49+
@Test
50+
public void autowireMetadataIsPropagated() {
51+
@Configuration class Config {
52+
@Bean(autowire=Autowire.BY_TYPE) Object foo() { return null; }
53+
}
54+
55+
assertEquals("autowire mode was not propagated",
56+
AbstractBeanDefinition.AUTOWIRE_BY_TYPE, beanDef(Config.class).getAutowireMode());
57+
}
58+
4759
@Test
4860
public void initMethodMetadataIsPropagated() {
4961
@Configuration class Config {
@@ -138,7 +150,7 @@ public void eagerBeanOverridesDefaultLazyConfiguration() {
138150

139151
@Test
140152
public void eagerConfigurationProducesEagerBeanDefinitions() {
141-
@Lazy(false) @Configuration class Config { // will probably never happen, doesn't make much sense
153+
@Lazy(false) @Configuration class Config { // will probably never happen, doesn't make much sense
142154
@Bean Object foo() { return null; }
143155
}
144156

0 commit comments

Comments
 (0)