Saturday, January 2, 2016

Spring MVC Test answers 2016.

Find Complete and recently updated Correct Question and answers of Spring MVC Test of Upwork. All Answers updated regularly with new questions. Upwork Spring MVC Test answers of 2016.



Question:* Which of the following code samples will get the ServletContext inside an Interceptor?

Answer: • @Autowired ServletContext context;

Answer: • request.getSession().getServletContext();

Question:* How can an HTTP 404 status code be returned from a Spring MVC Controller?

Answer: • Throwing a ResourceNotFoundException declared with the @ResponseStatus annotation.

Answer: • Having the method accept HttpServletResponse as a parameter, so that setStatus(404) can be called on it.

Question:* Which of the following interfaces can be implemented to interact with a container's management of the bean lifecycle?

Answer: • InitializingBean

Answer: • DisposableBean

Question:* Which of the following can be used to serve static resources while still using DispatchServlet at the site's root?

Answer: • <mvc:resources/>

Answer: • <mvc:default-servlet-handler/>

Question:* Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?

Answer: • @RequestMapping("/photo") public ResponseEntity<byte[]> testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); }

Answer: • @ResponseBody @RequestMapping("/photo", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); return IOUtils.toByteArray(in); }

Question:* Which of the following annotations are supported by classes with the @Bean annotation?

Answer: • @PostConstruct

Answer: • @PreDestroy

Question:* Which of the following statements is false?

Answer: • By default, a transaction is only marked for rollback in the case of runtime unchecked exceptions.

Question:* Which of the following statements is true about the HandlerExceptionResolver class?

Answer: • DefaultHandlerExceptionResolver converts standard Spring exceptions and converts them to HTTP Status Codes.

Question:* Which of the following statements is true about method arguments that have an @ModelAttribute annotation?

Answer: • Model attributes have to be explicitly added when using @ModelAttribute.

Question:* Given the following method: @RequestMapping(method=RequestMethod.GET, value="/fooBar") public ResponseEntity<String> fooBar2() { String json = "jsonResponse"; HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_JSON); return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED); } Which of the following statements is correct?

Answer: • It returns a JSON String and sets the mimetype to text/javascript.

Question:* Which of the following classes provides built-in pagination functionality in SpringMVC?

Answer: • PagedListHolder

Question:* Given the method below: @RequestMapping(value = "/foo", method = RequestMethod.GET) public final String foo(HttpServletRequest request, BindingResult bindResult, ModelMap model) { model.addAttribute("abc", 123); return "foo"; } When the view is displayed in the browser, it's URL is "http://mydomain/foo?abc=123". Which of the following statements is true?

Answer: • The attribute name-value pair will be included in the URL, regardless of the use of @ModelAttribute in the controller.

Question:* Which of the following is true about the use of <context:annotation-config /> in a servlet?

Answer: • <context:annotation-config> activates many different annotations in beans, whether they are defined in XML or through component scanning.

Question:* Which of the following are valid sets of constructor arguments for the ModelAndView class? (Select all correct answers.)

Answer: • String viewName, Map<String,?> model

Question:* Which of the following are possible validation methods for user input in Spring MVC?

Answer: • Annotation validation

Question:* Fill in the blank: The _______ enables the use of the bean element’s attributes, instead of nested <property/> elements, to describe property values and/or collaborating beans.

Answer: • p-namespace

Question:* Which of the following statements is true about the @RequestMapping annotation?

Answer: • It has a single String parameter.

Question:* Which of the following statements is true for the configuration of the Spring handler adapter(s) in a Spring MVC application context?

Answer: • If at least one request handler adapter is defined the context files, Spring will not create the default adapters.

Question:* What does the following code do? @RequestMapping("/{id}/**") public void foo(@PathVariable("id") int id, HttpServletRequest request) { String restOfTheUrl = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); ... }

Answer: • It retrieves the partial path value (after "**") before the @RequestMapping and @PathVariable values have been parsed.

Question:* Which of the following statements is true about the HandlerInterceptor interface?

Answer: • It allows exchanging the request and response objects that are handed down the execution chain.

Question:* Which of the following dependency injection (DI) methodologies are available in Spring MVC?

Answer: • Constructor-based dependency injection

Question:* Which of the following is the default bean scope in Spring MVC?

Answer: • singleton

Question:* True or false: a factory class can hold more than one factory method.

Answer: • True

Question:* Which of the following enables custom qualifier annotation types to be registered even if they are not annotated with Spring’s @Qualifier annotation?

Answer: • CustomAutowireConfigurer

Question:* Which of the following statements is correct?

Answer: • <mvc:resources> declares only DefaultAnnotationHandlerMapping by default.

Question:* Which of the following statements is true about the @RequestParam annotation?

Answer: • It indicates that a method parameter should be bound to a web request parameter.

Question:* Select all authentication methods that are supported by Spring Security by default:

Answer: • Digest Access Authentication

Question:* In an annotation-based Spring MVC controller, which of the following are valid ways to set cache headers for a specific path?

Answer: • Ensuring the instance of "AnnotationMethodHandlerAdapter" does not have the "cacheSeconds" property set, and adding an instance of "WebContentInterceptor".

Question:* What is the difference between the @Repository and the @Controller annotations in Spring?

Answer: • "@Repository" is used as a stereotype for the persistence layer, while "@Controller" is used as a stereotype for the presentation layer.

Question:* Which of the following statements are correct, with respect to using the @PreAuthorize annotation in Spring controller methods?

Answer: • @PreAuthorize works with Spring controller methods.

Question:* Which of the following is not a built-in Spring MVC bean scope?

Answer: • local session

Question:* Fill in the blank: _______ is a class-level annotation indicating that an object is a source of bean definitions.

Answer: • @Configuration

Question:* Regarding the @Resource annotation, which of the following statements is false?

Answer: • If no name attribute is specified, the default name is derived from the field name or setter method.

Question:* Fill in the blank: When defining a bean that is created with a static factory method, the ______ attribute is used to specify the class containing the static factory method.

Answer: • factory-class

Question:* Which of the following statements is true about the @ModelAttribute annotation?

Answer: • It can be used to expose reference data to a web view.

Question:* Fill in the blank: In Spring's XML-based configuration, the _______ attribute of the <property/> element specifies a property or constructor argument as a string representation.

Answer: • name

Question:* Which of the following statements is/are true about autowiring in Spring?

Answer: • Fields are injected after the construction of a bean.

Question:* Regarding dependency resolution, which of the following statements is false?

Answer: • Configuration metadata can only be specified via XML or annotations.



No comments:

Post a Comment