wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Spring Web

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

What does MVC stand for? (Choose one.)

a)

management versus control

b)

model-view-controller

c)

model verbosity clearance

d)

model view conventions

2.

Which Spring library is needed in your classpath to write a full-blown Spring web application? (Choose one.)

a)

spring-core.jar is enough

b)

spring-core.jar and spring-context.jar are enough

c)

spring-web.jar is enough

d)

spring-webmvc.jar is a must because that is where the DispatcherServlet class is

3.

What is the purpose of the @Controller annotation? (Choose one.)

a)

to indicate that the bean is to be encapsulated in a special Web Proxy

b)

to indicate that the class is to be used as a template to create a special type of bean required in a Spring web application to provide handler methods for requests

c)

to declare a class as the configuration class for a Spring web application

4.

Which scopes are web specific? (Choose all that apply.)

a)

SCOPE_SESSION

b)

SCOPE_THREAD

c)

SCOPE_SINGLETON

d)

SCOPE_APPLICATION

e)

SCOPE_REQUEST

5.

Given the following controller class containing a single handler method, which of the following URLs will be handled by that method? (Choose one.)
@Controller
@RequestMapping("/persons")
public class PersonController {
@RequestMapping(value = "/showPerson")
public String show(@RequestParam("personId") Long id, Model model) {
...
}
}

6.

Which class in the following list is the default view resolver in Spring: (Choose one.)

a)

JspResourceViewResolver

b)

ResourceViewResolver

c)

InternalResourceViewResolver

7.

What is wrong with the following controller class declaration? (Choose one.)
@ControllerAdvice
public class PersonsController {
@ExceptionHandler(NotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handle(NotFoundException ex) {
ModelAndView mav = new ModelAndView();
mav.addObject("problem", ex.getMessage());
mav.setViewName("error");
return mav;
}
}

a)

Nothing.

b)

This is not a controller class declaration, but a special type of bean used for handling exceptions thrown by handler methods.

c)

The handle() method is not allowed to return an instance of ModelAndView

d)

The handler method should be annotated with @RequestMapping or one of its specializations.

8.

Which of the following is true about the @WebMvcTest annotation? (Choose all that apply.)

a)

This annotation is the one to use when a test focuses only on Spring MVC components.

b)

This annotation has the effect of disabling auto-configuration and apply only configuration relevant to MVC tests.

c)

This annotation can be applied to a test class to enable and configure auto-configuration of MockMvc.

9.

When running a Spring Boot MVC test annotated with the following: @SpringBootTest(webEnvironment = SpringBootTest. WebEnvironment.RANDOM_PORT) How can the port value be retrieved? (Choose one.)

a)

Declare a local integer property and annotate it with @LocalServerPort

b)

Declare a local integer property and annotate it with @TestServerPort

c)

Make the test class extend SpringBootWebTest and call the getLocalServerPort()