Skip to content

Commit

Permalink
Improve documentation for FullyQualifiedAnnotationBeanNameGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jan 8, 2020
1 parent b4c91e7 commit e3e7d90
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
Expand Down Expand Up @@ -116,11 +116,13 @@ public void setEnvironment(ConfigurableEnvironment environment) {
/**
* Provide a custom {@link BeanNameGenerator} for use with {@link AnnotatedBeanDefinitionReader}
* and/or {@link ClassPathBeanDefinitionScanner}, if any.
* <p>Default is {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}.
* <p>Default is {@link AnnotationBeanNameGenerator}.
* <p>Any call to this method must occur prior to calls to {@link #register(Class...)}
* and/or {@link #scan(String...)}.
* @see AnnotatedBeanDefinitionReader#setBeanNameGenerator
* @see ClassPathBeanDefinitionScanner#setBeanNameGenerator
* @see AnnotationBeanNameGenerator
* @see FullyQualifiedAnnotationBeanNameGenerator
*/
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
this.reader.setBeanNameGenerator(beanNameGenerator);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2020 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.
Expand Down Expand Up @@ -94,6 +94,8 @@
* {@link AnnotationBeanNameGenerator} or any custom instance supplied to the
* application context at bootstrap time.
* @see AnnotationConfigApplicationContext#setBeanNameGenerator(BeanNameGenerator)
* @see AnnotationBeanNameGenerator
* @see FullyQualifiedAnnotationBeanNameGenerator
*/
Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;

Expand Down
Expand Up @@ -25,6 +25,11 @@
* a supported type-level annotation such as {@code @Component} (see
* {@link AnnotationBeanNameGenerator} for details on supported annotations).
*
* <p>Favor this bean naming strategy over {@code AnnotationBeanNameGenerator} if
* you run into naming conflicts due to multiple autodetected components having the
* same non-qualified class name (i.e., classes with identical names but residing in
* different packages).
*
* <p>Note that an instance of this class is used by default for configuration-level
* import purposes; whereas, the default for component scanning purposes is a plain
* {@code AnnotationBeanNameGenerator}.
Expand Down
13 changes: 10 additions & 3 deletions src/docs/asciidoc/core/core-beans.adoc
Expand Up @@ -6941,12 +6941,19 @@ classes were detected, the names would be `myMovieLister` and `movieFinderImpl`:
}
----

NOTE: If you do not want to rely on the default bean-naming strategy, you can provide a
custom bean-naming strategy. First, implement the
If you do not want to rely on the default bean-naming strategy, you can provide a custom
bean-naming strategy. First, implement the
{api-spring-framework}/beans/factory/support/BeanNameGenerator.html[`BeanNameGenerator`]
interface, and be sure to include a default no-arg constructor. Then, provide the fully
qualified class name when configuring the scanner, as the following example annotation
and bean definition show:
and bean definition show.

TIP: If you run into naming conflicts due to multiple autodetected components having the
same non-qualified class name (i.e., classes with identical names but residing in
different packages), you may need to configure a `BeanNameGenerator` that defaults to the
fully qualified class name for the generated bean name. As of Spring Framework 5.2.3, the
`FullyQualifiedAnnotationBeanNameGenerator` located in package
`org.springframework.context.annotation` can be used for such purposes.

[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
Expand Down

0 comments on commit e3e7d90

Please sign in to comment.