Spring Boot Properties & Configuration MCQ - - Multiple Choice Questions and Answers

Dive deep into the world of Spring Boot with a focus on properties and configuration. Spring Boot offers an elegant solution to the age-old problem of configuration management in large applications. Through the use of properties, developers can control various aspects of an application without diving into the codebase. 

Whether you're just starting out with Spring Boot or want to brush up on your knowledge, this MCQ guide centered around Spring Boot Properties & Configuration is your go-to resource. Let's get started!

1. Which file is primarily used to define properties in a Spring Boot application?

a) spring.properties
b) boot.properties
c) application.properties
d) config.properties

Answer:

c) application.properties

Explanation:

In a Spring Boot application, application.properties is the primary file to define configuration properties.

2. If you want to use YAML instead of properties for configuration in Spring Boot, which file would you create?

a) spring.yaml
b) boot.yaml
c) application.yaml
d) config.yaml

Answer:

c) application.yaml

Explanation:

Spring Boot supports YAML for configuration, and the file name used is application.yaml.

3. How can you access properties defined in application.properties in your Java class?

a) @PropertySource
b) @PropertyValue
c) @Value
d) @InjectProperty

Answer:

c) @Value

Explanation:

The @Value annotation is used to inject property values from application.properties into Java classes.

4. Which annotation enables type-safe property binding in Spring Boot?

a) @PropertyBind
b) @ConfigurationProperties
c) @BindProperties
d) @PropertiesConfiguration

Answer:

b) @ConfigurationProperties

Explanation:

The @ConfigurationProperties annotation enables type-safe property binding in Spring Boot.

5. Which of the following properties will set the application's logging level to DEBUG for all packages?

a) logging.level.root=DEBUG
b) log.level=DEBUG
c) application.log=DEBUG
d) spring.log.level=DEBUG

Answer:

a) logging.level.root=DEBUG

Explanation:

The logging.level.root property sets the logging level for all packages in the application.

6. What is the default properties file name for profile-specific configurations in Spring Boot?

a) application-<profile>.properties
b) spring-<profile>.properties
c) boot-<profile>.properties
d) config-<profile>.properties

Answer:

a) application-<profile>.properties

Explanation:

For profile-specific configurations, the default file name pattern is application-<profile>.properties.

7. How can you specify active profiles for your Spring Boot application?

a) spring.active.profiles
b) spring.profiles.active
c) application.profiles.active
d) spring.boot.profiles.active

Answer:

b) spring.profiles.active

Explanation:

The spring.profiles.active property allows specifying which profiles are currently active.

8. In Spring Boot, where does the @PropertySource annotation look for properties files by default?

a) Classpath root
b) System environment
c) src/main/resources
d) src/main/config

Answer:

a) Classpath root

Explanation:

By default, the @PropertySource annotation looks for properties files at the classpath root.

9. If both application.properties and application.yaml are present, which one takes precedence?

a) application.properties
b) application.yaml
c) Both merge their properties
d) Whichever is loaded last

Answer:

d) Whichever is loaded last

Explanation:

If both files are present, properties from the file that is loaded last will take precedence.

10. Which property helps specify external configuration directories for Spring Boot?

a) spring.config.location
b) spring.properties.external
c) spring.config.external
d) application.config.location

Answer:

a) spring.config.location

Explanation:

The spring.config.location property specifies external directories for Spring Boot configuration.

11. What does the spring.main.banner-mode property control?

a) Application mode (e.g., dev, prod)
b) The appearance of the Spring Boot banner at startup
c) Logging mode
d) Main application class configuration

Answer:

b) The appearance of the Spring Boot banner at startup

Explanation:

The spring.main.banner-mode property controls the appearance and behavior of the Spring Boot banner during application startup.

12. What will the property spring.datasource.initialize set to false do?

a) Disable the database connection
b) Prevent Spring Boot from initializing the database using Hibernate
c) Prevent Spring Boot from initializing the database using data.sql
d) None of the above

Answer:

c) Prevent Spring Boot from initializing the database using data.sql

Explanation:

Setting spring.datasource.initialize to false will prevent Spring Boot from automatically initializing the database using the data.sql script.


Related Spring Boot MCQ Posts

Comments