Java Spring Interview Questions

Practice for Java Spring interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your Java Spring skills for an upcoming job interview? Try solving these Java Spring interview questions that test knowledge of Spring Framework concepts such as scheduling, configuration, database abstraction, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These Java Spring interview questions are examples of real tasks used by employers to screen job candidates such as Java developers, web developers, Spring Framework developers, and others that require knowledge of the Java programming language and the Spring Framework.

1. Multiple Databases

Java Spring Database Abstraction Spring Boot New Public

A company wants to use Spring Boot in a web application which should use JPA as a database abstraction. The unit tests should be run on an H2 database while the production should run on a MySQL database.

Select all the things that need to be done or that will be done automatically by Spring Boot.

(Select all acceptable answers.)

Solve Question

2. Task Executor

Java Spring Configuration Public

Consider the following Spring bean:

public class TaskExecutor {

    private int threadCount;
    private String threadNameTemplate;
    private AtomicInteger counter = new AtomicInteger();
    private ExecutorService executorService;

    public void init() {
        ThreadFactory threadFactory = (runnable) -> new Thread(threadNameTemplate + counter.incrementAndGet());
        executorService = Executors.newFixedThreadPool(threadCount, threadFactory);

Select the statements that are correct.

(Select all acceptable answers.)

Solve Question

3. Weather Forecast Service

Java Spring Scheduling Public

Edit the WeatherForecastService, FakeThermometer, and the Config classes so that:

  • The Spring container should always return a new instance of FakeThermometer.
  • Config class will configure Spring scheduling.
  • takeTemperatureMeasurement method should be executed every 50 milliseconds, using Spring scheduling.
Solve Question

4. Movie Repository

Java Spring Database Abstraction New Public

The MovieRepository class is used in a Spring Boot web application about old movies.

Modify the findMoviesByName method of the MovieRepository class so that it uses JdbcTemplate to return all Movies that start with the nameStartsWith string. The returned list should contain Movie objects with the name, year, and rating fields correctly set.

The following class, provided here and below, is used to configure Spring:

class Config {
    public DriverManagerDataSource dataSource() {
        DriverManagerDataSource ds = new DriverManagerDataSource();
        return ds;
    public JdbcTemplate jdbcTemplate(DriverManagerDataSource ds) {
        return new JdbcTemplate(ds);

For example, executing the following code:

AnnotationConfigApplicationContext config = new AnnotationConfigApplicationContext();
MovieRepository repository = config.getBean(MovieRepository.class);

repository.createMovie("Some movie", 1974, 3);
repository.createMovie("Some other movie", 1993, 2);
repository.createMovie("Another movie", 1993, 2);

List<Movie> movies = repository.findMoviesByName("Some");
for(Movie movie : movies) {
    System.out.println( + " - " + movie.year + " - " + movie.rating);

should print:

Some movie - 1974 - 3
Some other movie - 1993 - 2
Solve Question

5. Logger AOP

Java Spring Configuration New Public

In the LoggerAOP class, using Spring AOP, intercept all calls to the public methods annotated with the LogExecution annotation, and call the log method on the logger field with the intercepted method's name as the data argument.

For example, calling the getNames method of the NameRepository class, which has LogExecution annotation, should print "getNames".

Solve Question

If you feel ready, take one of our timed public Java Spring Interview Questions tests:

Java and Spring Boot Online Test (Easy / Hard)

Java and Spring Framework Online Test (Easy / Hard)

Java, Hibernate, and Spring Boot Online Test (Easy / Hard)

Java, Hibernate, and Spring Framework Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers