Harmonize ConfigurationProperties bean name

When `@EnableConfigurationProperties` is defined, Spring Boot
automatically registers a bean in the context for each class specified
on the annotation. Previously, the name of the bean only included the
prefix which leads to conflict if two different classes use the same
prefix.

This commit changes the bean name structure to be <prefix>-<fqn> where
prefix is the prefix used on the annotation and <fqn> the fully qualified
name of the target class.

Closes gh-4395
This commit is contained in:
Stephane Nicoll
2016-02-09 17:19:11 +01:00
parent 2b18e99ac7
commit ebffa493e4
6 changed files with 25 additions and 9 deletions

View File

@@ -762,6 +762,18 @@ definitions by simply listing the properties classes directly in the
}
----
[NOTE]
====
When `@ConfigurationProperties` bean are registered that way, the bean will have a
conventional name: `<prefix>-<fqn>`, where `<prefix>` is the environment key prefix
specified in the `@ConfigurationProperties` annotation and <fqn> the fully qualified
name of the bean. If the annotation does not provide any prefix, only the fully qualified
name of the bean is used.
The bean name in the example above will be `connection-com.example.ConnectionSettings`,
assuming that `ConnectionSettings` sits in the `com.example` package.
====
TIP: Using `@ConfigurationProperties` also allows you to generate meta-data files that can
be used by IDEs. See the <<configuration-metadata>> appendix for details.