DEV Community

Cover image for Top 10 Free Spring Certification Practice Questions and Answers

Posted on • Updated on


Top 10 Free Spring Certification Practice Questions and Answers

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided in this article.

Hello Java developers, are you preparing for IT certification like Oracle's Java certification or Vmware's Spring Certification required a lot of hard-work.

I have seen many experienced Java developers failing these certifications and losing money and time due to over-confidence and lack of preparation. A structured and complete certification preparation involves reading books, joining course and doing practice questions.

When it comes to Spring certification, practice questions are quite hard to find and that's why I created my Udemy course with 250+ Spring Certification questions. This course has helped more than 9000 students in their Spring certification preparation journey.

Since many of you asked me about Free Spring certification questions, I decided to post 50 practice questions from my paid Spring certification course for FREE in a series of articles, just for you, my readers and motivators.

This also makes a lot of sense because I have in past used many free resources to pass my own Java and Spring certification and this way I can give something back to the community.

It will also helps me to get more feedback to improve the paid course even better to provide better learning experience to people who have trusted me with their money.

By the way, if you are in hurry, you can always join the full course on Udemy where you will get all questions and answers and start practicing with Udemy's exam simulator.

In the full course you will get:

  • 5 Full length practice tests
  • 250+ Questions with Answers and explanations
  • Topic wise questions like you can practice all spring boot or spring security questions
  • Lifetime access
  • 30-days money back guarantee with no questions asked

If you like to buy the course you can use this link to buy the course with the best price available. I usually give $9.9 discount coupon to my readers, so if you ever need, you can always ask in the comments below or you can drop me an email.

50 Free Spring Professional Certification Practice Questions with Answers and Explanations

10 Spring Framework Practice Questions Answers and Explanations

Here is 10 Spring questions you can solve or practice as part of your Spring professional certification.

These questions are from full length test which means they cover almost every topics like Core Spring, Bean lifecycle, AOP, Spring Boot, Testing, Microservices, Spring Data JPA and more.

1. Which of the following Spring MVC-related information types are collected in metrics by Spring Boot Actuator by default?

1. Requesting user

2. HTTP method

3. Accessed endpoint

4. Response status

Correct answer is 2,3,4

Explanation: By default, Spring MVC-related metrics are tagged with the following information:

  • exception - Simple class name of any exception that was thrown while handling the request.
  • method - Request' s method (for example, GET or POST)
  • outcome - Request's outcome based on the status code of the response. 1xx is INFORMATIONAL, 2xx is SUCCESS, 3xx is REDIRECTION, 4xx CLIENT_ERROR, and 5xx is SERVER_ERROR
  • status - Response's HTTP status code (for example, 200 or 500)
  • uri - Requests URI template prior to variable substitution, if possible (for example, /api/person/{id})

2. What do SpEL expressions starting with # reference?

1. Properties in the application environment

2. Spring Beans

3. Literal Values

4. JVM Properties

Correct Answer is 2 "Spring Beans"

Explanation: "A Spring bean is referenced using its name prefixed with @ in SpEL. Chains of property

references can be accessed using the period character.

  • Example accessing property on Spring bean: @mySuperComponent.injectedValue
  • Example invoking method on Spring bean: @mySuperComponent.toString()

3. Which of the following methods will be called first in the bean lifecycle?

1. afterPropertiesSet method in InitializingBean interface

2. init-method as specified in the Spring XML Configuration

3. Any methods annotated with @PostConstruct

4. Any method named "init"

Correct Answer is 3"Any methods annotated with @PostConstruct"

Explanation: For each bean in the container the lifecycle happens as follows:

An instance of the bean is created using the bean metadata.

Properties and dependencies of the bean are set.

Any instances of BeanPostProcessor are given a chance to process the new bean

instance before and after initialization.

  • Any methods in the bean implementation class annotated with @PostConstruct are


This processing is performed by a BeanPostProcessor.

  • Any afterPropertiesSet method in a bean implementation class implementing the

InitializingBean interface is invoked.

This processing is performed by a BeanPostProcessor. If the same initialization

method has already been invoked, it will not be invoked again.

  • Any custom bean initialization method is invoked.

Bean initialization methods can be specified either in the value of the init-method

attribute in the corresponding element in a Spring XML configuration or in

the initMethod property of the @Bean annotation.

This processing is performed by a BeanPostProcessor. If the same initialization

method has already been invoked, it will not be invoked again.

  • The bean is ready for use.

4. Which of the following are auto-configured when using @DataJpaTest?

1. Spring Repositories

2. Spring Security

3. DataSource

4. Message source

Correct Answer is 1,3

Explanation: "The @DataJpaTest annotation auto-configures the following:

  • Caching

  • Spring Data JPA repositories

  • Flyway database migration tool

  • A DataSource - The data-source will, as default, use an embedded in-memory database (test database).

  • Data source transaction manager - A transaction manager for a single DataSource.

  • A JdbcTemplate

  • Liquibase database migration tool

  • JPA based configuration for Hibernate

  • Spring transaction

  • A test database

  • A JPA entity manager for tests

5. What one of these ensures that if anything goes wrong, the changes will be preserved once the system is back?

1. Atomicity

2. Consistency

3. Isolation

4. Durability

Correct Answer: 4

Explanation: The effect of one transaction will not have any impact on another transaction so they are independent to one another. They are totally isolated from one another.

6. Which of the following properties are required in order to configure an external MySQL Database?

1. spring.datasource.password

2. spring.datasource.username

3. spring.datasource.url

4. spring.datasource.driver-class-name

Correct Answer: 1,2,3,4

Explanation: All of these are required. Depending on the Database Provider, sometimes it is not necessary to provide the driver-class-name.

7. Which class is used for programmatic usage of transactions?

1. TransactionTemplate

2. TransactionExecutor

3. @Transactional

4. RollbackManager

Correct Answer: 1

Explanation: @Transactional annotation in Spring is used for declarative usage, not programmatic.

8. What effect does setting the attribute "readOnly" on the @Transactional annotation to true have?

1. It does not allow write operations

2. It may optimize query performance

3. Sets the lock mode to READ

4. Nothing. It is there only for documentation.

Correct Answer is 2 "

Explanation: Only some databases reject the INSERT and UPDATE statements inside a read only transaction.

9. Which of the following does Spring Boot provide regarding error handling?

1. Global error page

2. JSON error response

3. Checked exceptions for most common problems

4. Logging errors stack traces separately

Correct Answer: 1,2

Explanation: By default, Spring Boot provides an /error mapping that handles all errors in a sensible way, and it is registered as a "global error page" in the servlet container. For machine clients, it produces a JSON response with details of the error, the HTTP status, and the exception message.

For browser clients, there is a "whitelabel" error view that renders the same data in HTML format (to customize it, add a View that resolves to error).  Spring only throws unchecked exceptions in the case of problems.

10. Which of the following are web environment options offered by @SpringBootTest?


2. WEB



Correct Answer: 1,4

Explanation: Four different types of web environments can be specified using the webEnvironment attribute of the @SpringBootTest annotation:

  • MOCK - Loads a web ApplicationContext and provides a mock web environment. Does not start a web server.
  • RANDOM_PORT - Loads a WebServerApplicationContext, provides a real web environment and starts an embedded web server listening on a random port. The port allocated can be obtained using the @LocalServerPort annotation or @Value(""${local.server.port}""). Web server runs in a separate thread and server-side transactions will not be rolled back in transactional tests.
  • DEFINED_PORT - Loads a WebServerApplicationContext, provides a real web environment and starts an embedded web server listening on the port configured in the application properties, or port 8080 if no such configuration exists. Web server runs in a separate thread and server-side transactions will not be rolled back in transactional tests.
  • NONE - Loads an ApplicationContext without providing any web environment.

That's all in this first list of 10 Spring Questions for practice. In the next list I will share 10 more question, I Am also thinking to categories them on topics like Spring Data JPA questions, Spring security questions, and Spring MVC questions for better learning experience. If you like guys like that way, I will do accordingly.

All the best with your Spring certification preparation.

Other Interview Questions and Articles for Java programmer:

P.S. - If you want to learn Spring 6 and Spring Boot 4 from scratch in a guided, code-focused way, I also suggest you check out Eugen Paraschiv's Learn Spring: The Master Class for more in-depth learning of spring framework.

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.