Sample questions
Question 1Easy
Which file does Spring Boot read for configuration by default?
- application.properties
- config/spring-settings.xml
- WEB-INF/web.xml
- settings.json in the project root
Answer: A. application.properties
Explanation
Both formats are supported in src/main/resources.
Step-by-step solution
- Spring Boot reads application.properties from src/main/resources by default.
- Both application.properties and application.yml are supported there.
- So the default file is option A.
Why the other options are wrong
- B. Config/spring-settings.xml is not a default Spring Boot file.
- C. WEB-INF/web.xml belongs to classic Java web apps, not Boot's default configuration.
- D. settings.json in the project root is not read by default.
Tip: The default config files are application.properties or application.yml in src/main/resources.
Question 2Easy
How do you activate the 'prod' profile?
- spring.profiles.active=prod
- profile.enable=prod
- @Prod on the main class
- spring.profile=prod
Answer: A. spring.profiles.active=prod
Explanation
It can be set in properties, as an environment variable (SPRING_PROFILES_ACTIVE) or a command-line argument.
Step-by-step solution
- Profiles are chosen with the spring.profiles.active property.
- Setting it to prod activates the prod profile.
- So the correct line is option A, spring.profiles.active=prod.
Why the other options are wrong
- B. profile.enable is not a Spring property.
- C. @Prod is not a built-in annotation for activating a profile.
- D. spring.profile is not the key; the key is spring.profiles.active.
Tip: Use spring.profiles.active; it can also be set as an environment variable or a command-line argument.
Question 3Easy
Which property sets the JDBC URL for the auto-configured DataSource?
- spring.jpa.url
- jdbc.address
- db.connection
- spring.datasource.url
Answer: D. spring.datasource.url
Explanation
spring.datasource.username and password go alongside it.
Step-by-step solution
- Datasource settings live under the spring.datasource prefix.
- The URL is spring.datasource.url.
- Username and password go beside it.
Why the other options are wrong
- A. There is no spring.jpa.url.
- B. Not a Boot property.
- C. Not a Boot property.
Question 4Easy
Which property changes the server port?
- http.port
- tomcat.listen
- server.port
- spring.port
Answer: C. server.port
Explanation
For example, server.port=9090.
Step-by-step solution
- Spring Boot reads server settings from keys that start with server.
- The port key is server.port.
- For example, server.port=9090 sets the port, so the answer is option C.
Why the other options are wrong
- A. http.port is not a Spring Boot property.
- B. tomcat.listen is not a Spring Boot property.
- D. spring.port is not the key for the server port.
Tip: Server settings start with server., for example server.port.
Question 5Medium
In application.yml, nested keys like spring: datasource: url: are equivalent to which properties key?
- spring_datasource_url
- spring-datasource-url
- spring.datasource.url
- datasource.spring.url
Answer: C. spring.datasource.url
Explanation
YAML hierarchy maps to dot-separated property names.
Step-by-step solution
- YAML nests keys as indented blocks: spring, then datasource, then url.
- Boot flattens this nesting into dot-separated property names.
- So spring: datasource: url: is equivalent to spring.datasource.url, option C.
Why the other options are wrong
- A. Underscores are not how nested YAML keys map to property names.
- B. Dashes are not the nesting separator; the dots are.
- D. The order is wrong; the nesting gives spring first, then datasource, then url.
Tip: Each nested YAML level becomes one dot-separated part of the property name.
Question 6Medium
Where should application.properties be placed in a standard Maven project so it is on the classpath?
- src/main/java
- src/test/java
- src/main/resources
- target/
Answer: C. src/main/resources
Explanation
Resources are copied to the classpath root at build time.
Step-by-step solution
- Maven copies files from src/main/resources to the classpath root at build time.
- An application.properties placed there is found by Spring Boot on the classpath.
- So the location is option C, src/main/resources.
Why the other options are wrong
- A. Src/main/java holds Java source code, not resource files.
- B. Src/test/java holds test code and is not on the main classpath.
- D. Target/ is the build output folder; you do not place source files there.
Tip: Put config files in src/main/resources; Maven copies them to the classpath.
Question 7Medium
Which annotation enables validation of a @ConfigurationProperties class at startup?
- @Validated
- @Valid on the main class
- @Checked
- @Strict
Answer: A. @Validated
Explanation
With @Validated and constraints such as @NotBlank, invalid configuration stops startup with a clear error.
Step-by-step solution
- Constraints such as @NotBlank are checked only when validation is enabled.
- Adding @Validated to the @ConfigurationProperties class enables that validation.
- So the annotation is option A, @Validated.
Why the other options are wrong
- B. @Valid is placed on fields or parameters, not on the main class.
- C. @Checked is not a Spring validation annotation.
- D. @Strict is not a Spring validation annotation.
Tip: Put @Validated on the properties class and constraint annotations on its fields.
Question 8Medium
@ConfigurationProperties(prefix = "mail") on a class with a host field binds:
- spring.mail.host only
- MAIL
- mail.host
- host.mail
Answer: C. mail.host
Explanation
The prefix plus field name forms the property key.
Step-by-step solution
- @ConfigurationProperties with prefix mail binds properties under the mail prefix.
- The host field is then bound to the key made from the prefix and the field name.
- So the key is option C, mail.host.
Why the other options are wrong
- A. spring.mail.host needs the prefix spring.mail, which this class does not use.
- B. MAIL is only the prefix in uppercase; the full key also includes the field name.
- D. The order is reversed; the prefix comes first, then the field name.
Tip: Property key = prefix, then a dot, then the field name.
Question 9Hard
Which statement about @Value on a static field is correct?
- It works exactly like instance fields
- It makes the property read-only
- It isn't injected
- It injects at compile time
Answer: C. It isn't injected
Explanation
Injection targets bean instances; static fields are left untouched.
Step-by-step solution
- Spring injects @Value into bean instances, which hold instance fields.
- A static field belongs to the class, not to a bean instance, so Spring leaves it untouched.
- So a static field is not injected, option C.
Why the other options are wrong
- A. Static fields do not follow the instance injection rules.
- B. The field is not made read-only; it is simply not injected.
- D. Injection happens when the bean is created at runtime, not at compile time.
Tip: Inject @Value into an instance field or a constructor parameter, not a static field.
Question 10Hard
Two profiles are active: 'common' and 'prod', both defining db.pool=10 and db.pool=50 respectively, activated as spring.profiles.active=common,prod.
Which value wins?
- 10
- 50
- 60
- Startup fails
Answer: B. 50
Explanation
When several profiles set the same property, the last active profile wins.
Step-by-step solution
- Both profiles are active.
- Profile-specific files are loaded in order of the list.
- The later profile (prod) overrides the earlier one, so db.pool = 50.
Why the other options are wrong
- A. That is the earlier profile's value and is overridden.
- C. Values are not added together.
- D. Duplicate keys across profiles are allowed.
Tip: Last profile listed wins.
Practise all 15 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →