Spring Certified Professional 2023 · Free Practice Question Hard

Question 4

Which snippet binds foo.properties to Foo bean?


Consider Foo having :

  • A
  • B
  • C


  • D
Reveal correct answer

Correct answer: C

Explanation

ConfigurationProperties and PropertySource cannot be applied to a field.


So the only right answer is

https://github.com/vinny59200/UdemySPringFooProperties/blob/master/src/main/java/com/vv/foo_properties/config/Foo.java


https://mkyong.com/spring-boot/spring-boot-configurationproperties-example/




Spring doc:

* public @interface ConfigurationProperties

Annotation for externalized configuration. Add this to a class definition or a @Bean method in a @Configuration class if you want to bind and validate some external Properties (e.g. from a .properties file).

https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/properties/ConfigurationProperties.html

* public @interface PropertySource

Annotation providing a convenient and declarative mechanism for adding a PropertySource to Spring's Environment. To be used in conjunction with @Configuration classes.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need