When the @ConfigurationProperties bean is registered using configuration property scanning or via @EnableConfigurationProperties, the bean has a conventional name: <prefix>-<fqn>, where <prefix> is the environment key prefix specified in the @ConfigurationProperties annotation and <fqn> is 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.

If the annotation does not provide any prefix, only the fully qualified name of the bean is used. @ConfigurationProperties must have prefix The official document is wrong wrong at Note 2.8.3. Enabling @ConfigurationProperties-annotated types Note

Comment From: snicoll

Thanks for the report but this is the issue tracker of the Spring Framework. I am moving this to the appropriate issue tracker.

Comment From: snicoll

@ConfigurationProperties must have prefix The official document is wrong

As much as I'd like that to be true, the prefix is not mandatory. What part of the doc is wrong exactly?

Comment From: 15702992009

Prefix must be specified Inspection info: Verifies @ConfigurationProperties setup. New in 2018.3 SpringBoot Spring boot features document have a problem

Comment From: scottfrederick

That inspection failure is a bug in IntelliJ: https://youtrack.jetbrains.com/issue/IDEA-219436. Spring Boot does not require the prefix.

Comment From: snicoll

Thanks for the reference @scottfrederick. I don't think this is a bug in IJ but rather an inspection to point you towards a best practice. A prefix really should be set in practice.

Comment From: scottfrederick

Good points in your comment added to the IntelliJ issue @snicoll. Changing the inspection from an error to a warning and/or changing the message from Prefix must be specified to something like Prefix should be specified would be much better.

Comment From: 15702992009

Thank you very much. Recently i learn Spring Boot by reading Official doc and this is my first time in my life to commit a issue and get the answer immediately thanks again!!! @snicoll @scottfrederick

Comment From: Betlista

@snicoll Can you explain a bit more why this is a good practice?

With all the respect I do not agree with that.

Your point of view probably is (I'm just guessing), that by defining a prefix I can separate sections in a configuration file. My preference, on the other hand, is to have multiple configuration files instead of a single application.yml file, which I configured using -Dspring.config.additional-location=classpath:topic1.yml,classpath:topic2.yml.

So instead of having

topic1:
  foo: bar

topic2:
  foo: bar

I have sections in separate files and in such case, the prefix, as well as integration in a file, is not preferred.

And in relation to this, I'd like to have an easier way how to specify, that I have topic1 and topic2 instead of application.yml. Simplest seems to me to have spring.config.names (I added s to the end) which might accept a list of names similar to profiles.

Comment From: cyraid

@snicoll How are you gonna get properties from the root? At work I'm required to have a property in root. What prefix would I use for the root? (YAML)

i_need_this_property: "Some Value"
what_would_this_prefix_be: "?"

some_group:
  this_works_and_prefix_would_be: "some_group"
@ConfigurationProperties
public class SomeConfig {
  private String iNeedThisProperty;
} // Class //