From dee88d931a34a390626f13ed975d0bcf5c761053 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 3 Apr 2019 12:58:13 +0200 Subject: [PATCH] Common constant for DefaultBeanNameGenerator as well Closes gh-22591 --- .../factory/support/AbstractBeanDefinitionReader.java | 6 +++--- .../factory/support/DefaultBeanNameGenerator.java | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java index b734229bb895..a9a556caea4e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -61,7 +61,7 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead private Environment environment; - private BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator(); + private BeanNameGenerator beanNameGenerator = DefaultBeanNameGenerator.INSTANCE; /** @@ -171,7 +171,7 @@ public Environment getEnvironment() { *

Default is a {@link DefaultBeanNameGenerator}. */ public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) { - this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : new DefaultBeanNameGenerator()); + this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : DefaultBeanNameGenerator.INSTANCE); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultBeanNameGenerator.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultBeanNameGenerator.java index c0c287d988a3..9632f5a7115b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultBeanNameGenerator.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultBeanNameGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2019 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. @@ -27,6 +27,14 @@ */ public class DefaultBeanNameGenerator implements BeanNameGenerator { + /** + * A convenient constant for a default {@code DefaultBeanNameGenerator} instance, + * as used for {@link AbstractBeanDefinitionReader} setup. + * @since 5.2 + */ + public static final DefaultBeanNameGenerator INSTANCE = new DefaultBeanNameGenerator(); + + @Override public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { return BeanDefinitionReaderUtils.generateBeanName(definition, registry);