Skip to content

Commit dee88d9

Browse files
committed
Common constant for DefaultBeanNameGenerator as well
Closes gh-22591
1 parent 47c8d1d commit dee88d9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -61,7 +61,7 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead
6161

6262
private Environment environment;
6363

64-
private BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
64+
private BeanNameGenerator beanNameGenerator = DefaultBeanNameGenerator.INSTANCE;
6565

6666

6767
/**
@@ -171,7 +171,7 @@ public Environment getEnvironment() {
171171
* <p>Default is a {@link DefaultBeanNameGenerator}.
172172
*/
173173
public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) {
174-
this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : new DefaultBeanNameGenerator());
174+
this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : DefaultBeanNameGenerator.INSTANCE);
175175
}
176176

177177
@Override

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

+9-1
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-2019 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.
@@ -27,6 +27,14 @@
2727
*/
2828
public class DefaultBeanNameGenerator implements BeanNameGenerator {
2929

30+
/**
31+
* A convenient constant for a default {@code DefaultBeanNameGenerator} instance,
32+
* as used for {@link AbstractBeanDefinitionReader} setup.
33+
* @since 5.2
34+
*/
35+
public static final DefaultBeanNameGenerator INSTANCE = new DefaultBeanNameGenerator();
36+
37+
3038
@Override
3139
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
3240
return BeanDefinitionReaderUtils.generateBeanName(definition, registry);

0 commit comments

Comments
 (0)