WorksheetsSpring Web
Total questions: 9
Worksheet time: 5mins
What does MVC stand for? (Choose one.)
management versus control
model-view-controller
model verbosity clearance
model view conventions
Which Spring library is needed in your classpath to write a full-blown Spring web application? (Choose one.)
spring-core.jar is enough
spring-core.jar and spring-context.jar are enough
spring-web.jar is enough
spring-webmvc.jar is a must because that is where the DispatcherServlet class is
What is the purpose of the @Controller annotation? (Choose one.)
to indicate that the bean is to be encapsulated in a special Web Proxy
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
to declare a class as the configuration class for a Spring web application
Which scopes are web specific? (Choose all that apply.)
SCOPE_SESSION
SCOPE_THREAD
SCOPE_SINGLETON
SCOPE_APPLICATION
SCOPE_REQUEST
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) {
...
}
}
http://localhost:8080/mvc-basic/persons/ showPerson?personId=aa
http://localhost:8080/mvc-basic/persons/ showPerson?personId=105
Which class in the following list is the default view resolver in Spring: (Choose one.)
JspResourceViewResolver
ResourceViewResolver
InternalResourceViewResolver
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;
}
}
Nothing.
This is not a controller class declaration, but a special type of bean used for handling exceptions thrown by handler methods.
The handle() method is not allowed to return an instance of ModelAndView
The handler method should be annotated with @RequestMapping or one of its specializations.
Which of the following is true about the @WebMvcTest annotation? (Choose all that apply.)
This annotation is the one to use when a test focuses only on Spring MVC components.
This annotation has the effect of disabling auto-configuration and apply only configuration relevant to MVC tests.
This annotation can be applied to a test class to enable and configure auto-configuration of MockMvc.
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.)
Declare a local integer property and annotate it with @LocalServerPort
Declare a local integer property and annotate it with @TestServerPort
Make the test class extend SpringBootWebTest and call the getLocalServerPort()
