JOBSEEKER?

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: Practice yourself

Take a Practice 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
   
Easy  

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.)


2. Task Executor

Java Spring Configuration Public
   
Easy  

Consider the following Spring bean:

@Component
public class TaskExecutor {

    @Value("${thread.count:10}")
    private int threadCount;
    @Value("worker.thread.name")
    private String threadNameTemplate;
    private AtomicInteger counter = new AtomicInteger();
    private ExecutorService executorService;

    @PostConstruct
    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.)


3. Weather Forecast Service

Java Spring Scheduling New Public
   
Easy  

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.

4. Movie Repository

Java Spring Database abstraction New Public
   
Easy  

Modify the createMovie and findMoviesByName methods of the class MovieRepository.

  • Using JdbcTemplate, createMovie method should insert a new row into the movies table with the specified data.
  • Using JdbcTemplate, findMoviesByName should return a list of all movies from the 'movies' table, in which the name of the movie contains the likeName string, using the LIKE operator. The returned list should contain Movie objects with name, year, and rating fields correctly set.

For example, executing the following code:

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

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

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

should print:

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

5. Logger AOP

Java Spring Configuration New Public
   
Hard  

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.


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

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)

Spring MVC 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