Bird
Raised Fist0
Spring Bootframework~20 mins

Application.properties basics in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Application.properties Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the effect of this application.properties setting?
Given the following line in application.properties:

server.port=8081

What will be the port number your Spring Boot application listens on?
AThe application listens on port 8080 (default).
BThe application listens on port 8081.
CThe application listens on port 80.
DThe application will fail to start due to invalid port.
Attempts:
2 left
💡 Hint
The server.port property controls the HTTP port.
📝 Syntax
intermediate
2:00remaining
Which line correctly sets a custom application name in application.properties?
You want to set the application name to "MyApp" using application.properties. Which option is correct?
Aspring.application.name=MyApp
Bspring.application.name: MyApp
Cspring.application.name = "MyApp"
Dspring.application.name => MyApp
Attempts:
2 left
💡 Hint
Properties files use key=value format without quotes.
🔧 Debug
advanced
2:00remaining
What error occurs with this application.properties line?
Consider this line in application.properties:

spring.datasource.url jdbc:mysql://localhost:3306/db

What happens when Spring Boot tries to start?
ASpring Boot throws a <code>java.lang.IllegalArgumentException</code> due to invalid property syntax.
BSpring Boot starts normally and connects to the database.
CSpring Boot throws a <code>BeanCreationException</code> due to missing URL.
DSpring Boot ignores the line and uses default datasource URL.
Attempts:
2 left
💡 Hint
Check the syntax for key-value pairs in properties files.
❓ state_output
advanced
2:00remaining
What is the value of logging.level.root after loading this application.properties?
Given these lines in application.properties:

logging.level.root=INFO
logging.level.org.springframework=DEBUG

What is the effective logging level for the root logger?
AINFO
BDEBUG
CWARN
DERROR
Attempts:
2 left
💡 Hint
Specific package levels override root, but root applies globally.
🧠 Conceptual
expert
2:00remaining
Which statement about application.properties loading order is true?
In Spring Boot, which of these statements about application.properties loading order is correct?
AProperties in <code>src/main/resources/application.properties</code> override those in external config files.
BThe order of properties loading is random and unpredictable.
CProperties defined in <code>application.properties</code> are always overridden by environment variables.
DExternal configuration files have higher priority than packaged <code>application.properties</code>.
Attempts:
2 left
💡 Hint
Think about how Spring Boot prioritizes external vs internal config.

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

  1. Step 1: Understand the role of application.properties

    This file is used to store configuration settings in a simple key=value format.
  2. Step 2: Compare with other options

    Writing Java code, defining HTML templates, or managing database migrations are done elsewhere, not in this file.
  3. Final Answer:

    To store configuration settings as key=value pairs -> Option A
  4. 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

  1. Step 1: Recall Spring Boot property syntax

    Spring Boot uses dot notation with key=value pairs in application.properties.
  2. Step 2: Identify correct key for server port

    The correct key is server.port, and the value is set with an equals sign.
  3. Final Answer:

    server.port=8081 -> Option A
  4. Quick Check:

    Dot notation + equals sign = correct syntax [OK]
Hint: Use dot notation and equals sign for properties [OK]
Common Mistakes:
  • Using underscores instead of dots
  • Using colon instead of equals sign
  • Swapping key parts order
3. Given this application.properties snippet:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=pass123

What will Spring Boot do with these properties when the app starts?
medium
A. Create a new database named 'mydb'
B. Ignore these properties because they are invalid
C. Start a web server on port 3306
D. Connect to MySQL database at localhost with given credentials

Solution

  1. Step 1: Identify datasource properties

    The keys starting with spring.datasource configure database connection details.
  2. Step 2: Understand Spring Boot behavior

    Spring Boot uses these to connect to the specified MySQL database with username and password.
  3. Final Answer:

    Connect to MySQL database at localhost with given credentials -> Option D
  4. Quick Check:

    Datasource properties = DB connection [OK]
Hint: Datasource keys configure DB connection automatically [OK]
Common Mistakes:
  • Thinking it starts a web server on DB port
  • Assuming properties are ignored
  • Believing it creates the database automatically
4. What is wrong with this application.properties line?
server.port-8080
medium
A. The port number 8080 is invalid
B. The key and value are separated by a dash instead of equals sign
C. The key should be port.server instead
D. There should be no spaces around the dash

Solution

  1. Step 1: Check property syntax

    Properties require key and value separated by an equals sign (=), not a dash (-).
  2. Step 2: Validate the key and value

    The key server.port is correct, and 8080 is a valid port number.
  3. Final Answer:

    The key and value are separated by a dash instead of equals sign -> Option B
  4. Quick Check:

    Use '=' to separate key and value [OK]
Hint: Always use '=' between key and value in properties [OK]
Common Mistakes:
  • Using dash instead of equals sign
  • Swapping key parts order
  • Thinking spaces fix the syntax
5. You want to add a custom property app.title in application.properties and access it in your Spring Boot code. Which of these steps is correct?
hard
A. Add app.title=MyApp in properties and access it with System.getenv("app.title")
B. Add app.title: MyApp in properties and read it with System.getProperty("app.title")
C. Add app.title=MyApp in properties and use @Value("${app.title}") in code
D. Add app.title=MyApp in properties and use @Autowired String app.title in code

Solution

  1. Step 1: Add custom property correctly

    Use key=value syntax: app.title=MyApp in application.properties.
  2. Step 2: Access property in Spring Boot code

    Use @Value("${app.title}") annotation to inject the property value.
  3. Final Answer:

    Add app.title=MyApp in properties and use @Value("${app.title}") in code -> Option C
  4. Quick Check:

    Custom property + @Value injection = correct [OK]
Hint: Use @Value("${key}") to inject properties in code [OK]
Common Mistakes:
  • Using colon instead of equals in properties
  • Trying to get property from environment variables
  • Incorrect use of @Autowired for simple values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard