What is the purpose of the application.properties file in a Spring Boot project?
It is used to configure application settings like server port, database connection, and other properties in a simple key-value format.
Click to reveal answer
beginner
How do you set the server port to 8081 in application.properties?
Add the line server.port=8081 to the application.properties file.
Click to reveal answer
beginner
Can you use application.properties to configure database connection details? Give an example.
Yes. For example: spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=secret
Click to reveal answer
intermediate
What happens if you have conflicting properties in application.properties and application.yml?
Spring Boot uses a priority order. Usually, application.properties and application.yml are merged, but if the same property is defined in both, the last one loaded wins. It's best to avoid conflicts.
Click to reveal answer
intermediate
How can you access a property defined in application.properties inside your Spring Boot Java code?
You can use the @Value annotation, for example: @Value("${property.name}") private String propertyName;
Click to reveal answer
Which file format is used for application.properties?
AJSON format
BXML format
CKey-value pairs separated by '='
DYAML format
✗ Incorrect
application.properties uses simple key-value pairs separated by '='.
How do you change the default server port in Spring Boot using application.properties?
Aserver.port=8081
Bport=8080
Cserver.port=8080
DserverPort=8081
✗ Incorrect
The correct property to change the port is server.port.
Which annotation allows you to inject a property value from application.properties into a Spring Boot component?
A@Autowired
B@PropertySource
C@Component
D@Value
✗ Incorrect
@Value is used to inject property values.
If you want to set a database URL in application.properties, which prefix is commonly used?
Aspring.datasource.
Bdatabase.url.
Cdb.connection.
Dspring.db.url.
✗ Incorrect
Spring Boot uses spring.datasource. prefix for database settings.
What is the file name for the default Spring Boot configuration file using properties format?
Aapplication.yaml
Bapplication.properties
Cconfig.properties
Dspring.properties
✗ Incorrect
The default configuration file is application.properties.
Explain how to configure the server port and database connection in application.properties.
Think about key-value pairs for server and database settings.
You got /4 concepts.
Describe how to access a property from application.properties inside a Spring Boot Java class.
Consider how Spring Boot injects configuration values.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of the application.properties file in a Spring Boot project?
easy
A. To store configuration settings as key=value pairs
B. To write Java code for the application
C. To define HTML templates for the UI
D. To manage database schema migrations
Solution
Step 1: Understand the role of application.properties
This file is used to store configuration settings in a simple key=value format.
Step 2: Compare with other options
Writing Java code, defining HTML templates, or managing database migrations are done elsewhere, not in this file.
Final Answer:
To store configuration settings as key=value pairs -> Option A
Quick Check:
Config file = key=value pairs [OK]
Hint: Remember: properties file holds settings, not code or templates [OK]
Common Mistakes:
Thinking it contains Java code
Confusing it with HTML or template files
Assuming it manages database migrations
2. Which of the following is the correct syntax to set the server port to 8081 in application.properties?
easy
A. server.port=8081
B. server-port: 8081
C. server_port=8081
D. port.server=8081
Solution
Step 1: Recall Spring Boot property syntax
Spring Boot uses dot notation with key=value pairs in application.properties.
Step 2: Identify correct key for server port
The correct key is server.port, and the value is set with an equals sign.
Final Answer:
server.port=8081 -> Option A
Quick Check:
Dot notation + equals sign = correct syntax [OK]
Hint: Use dot notation and equals sign for properties [OK]