MCQs > IT & Programming > Spring MVC MCQs > Basic Spring MVC MCQs

Basic Spring MVC MCQ

1. Which annotations will not allow you to apply bean property setter methods, non-setter methods, constructor and properties.

Answer

Correct Answer: @Isrequired
@Qualifier
@Required

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

2. Which of the following are AOP implementation?

Answer

Correct Answer: Spring AOP
JBoss AOP

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

3. What are the types of Advice?

Answer

Correct Answer: Before Advice
After returning advice
Around advice

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

4. Which of the following class is used for executing the SQL queries in Spring?

Answer

Correct Answer: JdbcTemplate

Note: This Question is unanswered, help us to find answer for this one

5.

Which statement best describes the  <context:annotation-config> tag for Spring XML configuration ?


Answer

Correct Answer:

activates annotations in beans only by component scanning.  


Note: This Question is unanswered, help us to find answer for this one

6.

Which code will allow you to share services in different applications?


Answer

Correct Answer:

@Service

public class CheckInService {

  @Resource

  private CheckInCleanup checkInCleanup;

  public void checkIn(Doc doc) {

    //...

    checkInCleanup.checkIn(doc)

  }

}


Note: This Question is unanswered, help us to find answer for this one

7. The target _________ is free to center on its major concern using the ________ concepts.

Answer

Correct Answer: Class
AOP

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

8. Choose the most probable reason why a Spring MVC bean correctly defined in a Java Configuration class is null in a Tomcat server?

Answer

Correct Answer: You need to correctly configure the context-parameters in the web-xml

Note: This Question is unanswered, help us to find answer for this one

9. The IoC container gets information from the ______ file.

Answer

Correct Answer: XML

Note: This Question is unanswered, help us to find answer for this one

10. What are the advantages of Spring Framework?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

11. Choose the best explanation as to how Spring MVC ensures the @Singelton scope when injecting beans defined in a Java Configuration?

Answer

Correct Answer: Spring proxies your class when annotated with @Configuration

Note: This Question is unanswered, help us to find answer for this one

12.

What is constructor mode of autowiring?


Answer

Correct Answer:

Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.


Note: This Question is unanswered, help us to find answer for this one

13. Weaving is used to create new proxy _______ by applying aspects to target object?

Answer

Correct Answer: Object

Note: This Question is unanswered, help us to find answer for this one

14. The core ____________ module provides the fundamental functionality of the spring framework.

Answer

Correct Answer: Container

Note: This Question is unanswered, help us to find answer for this one

15. Which Spring's RestTemplate class methods will return a ResponseEntity?

Answer

Correct Answer: getForEntity() and exchange()

Note: This Question is unanswered, help us to find answer for this one

16. Which statement best describes Spring Framework implementation of the Inversion of Control?

Answer

Correct Answer: A pattern that allows to build very decoupled systems

Note: This Question is unanswered, help us to find answer for this one

17. Which are the configuration types in Spring?

Answer

Correct Answer: XML-Based , Annotation Based, Java Based

Note: This Question is unanswered, help us to find answer for this one

18. Which of the following collection types are supported by Spring?

Answer

Correct Answer: list, set, map, props

Note: This Question is unanswered, help us to find answer for this one

19.

For the following Java configuration, Explain why the Cross Site Request Forgery protection is not correctly configured?

@EnableWebSecurity 

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override 

protected void configure(HttpSecurity http) throws Exception { 

    http .csrf().disable(); 

} }

Answer

Correct Answer:

Need to include the @Configuration annotation in the class definition 


Note: This Question is unanswered, help us to find answer for this one

20. The ____________ module provides class instrumentation support and classloader implementations to be used in certain application servers.

Answer

Correct Answer: Instrumentation

Note: This Question is unanswered, help us to find answer for this one

21. Which of the following can be used to provide configuration metadata to the Spring Container?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

22. Which of the following best describes the web module?

Answer

Correct Answer: The web module enables the creation of a web application without XML. The web.xml file needs to be configured for using the web module.

Note: This Question is unanswered, help us to find answer for this one

23.

Choose the correct expression needed to replace the error in the following code fragment for the Spring RestTemplate?


Answer

Correct Answer:

User returns = rt.postForObject(uri, u, User.class);


Note: This Question is unanswered, help us to find answer for this one

24. Which of the following is the best way to retrieve the response header for a RestTemplate post request?

Answer

Correct Answer: Use the RestTemplate exchange method and use responses getHeaders() method

Note: This Question is unanswered, help us to find answer for this one

25. Which statement is correct for @Controller annotation?

Answer

Correct Answer: The @Controller annotation indicates that a particular class serves the role of a controller. It does not require you to extend any controller base class or reference the Servlet API.

Note: This Question is unanswered, help us to find answer for this one

26. What are the modules of the core container?

Answer

Correct Answer: Core, Bean, Context, SpEL

Note: This Question is unanswered, help us to find answer for this one

27. The SpEL module provides a powerful expression ____________ for querying and manipulation of an object.

Answer

Correct Answer: Language

Note: This Question is unanswered, help us to find answer for this one

28. What are the benefits of IOC?

Answer

Correct Answer: Loose coupling is promoted with minimal effort and least intrusive mechanism.

Note: This Question is unanswered, help us to find answer for this one

29. Which class can be used to call Stored Procedures in Spring?

Answer

Correct Answer: SimpleJdbcCall

Note: This Question is unanswered, help us to find answer for this one

30.

Which is the best explanation as to why this Java configuration fails to correctly override / add a resource handler?


Answer

Correct Answer:

public class ApplicationContextConfig needs to extend Spring's WebMvcConfigurerAdapter


Note: This Question is unanswered, help us to find answer for this one

31. Choose the reason why the expression ${user.home} can be null despite the use of @PropertySource annotation?

Answer

Correct Answer: Need to use ${sys:user.home}

Note: This Question is unanswered, help us to find answer for this one

32.

Which statement best describes the <context:component-scan> tag for Spring XML configuration?


Answer

Correct Answer:

<context:component-scan> logically extends <context:annotation-config/>with CLASSPATH component scanning 


Note: This Question is unanswered, help us to find answer for this one

33. Which of the following is the most efficient way to serialize an Enum to JSON with Jackson 2.1?

Answer

Correct Answer: Annotate the Enum with @JsonFormat(shape= JsonFormat.Shape.OBJECT)

Note: This Question is unanswered, help us to find answer for this one

34. Which of the following ViewResolver class is widely used?

Answer

Correct Answer: org.springframework.web.servlet.view.InternalResourceViewResolver

Note: This Question is unanswered, help us to find answer for this one

35.

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

Correct Answer:

name


Note: This Question is unanswered, help us to find answer for this one

36. Which of the following statements is true about the @ModelAttribute annotation?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

37.

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

Correct Answer:

class


Note: This Question is unanswered, help us to find answer for this one

38. Regarding the @Resource annotation, which of the following statements is false?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: @Configuration

Note: This Question is unanswered, help us to find answer for this one

40. Which of the following annotations are supported by classes with the @Bean annotation?

Answer

Correct Answer: @PostConstruct

Note: This Question is unanswered, help us to find answer for this one

41. Which of the following is not a built-in Spring MVC bean scope?

Answer

Correct Answer: local session

Note: This Question is unanswered, help us to find answer for this one

42.

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

Answer

Correct Answer:

@PreAuthorize works with Spring controller methods.



Note: This Question is unanswered, help us to find answer for this one

43.

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

Answer

Correct 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); }



Note: This Question is unanswered, help us to find answer for this one

44.

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

Answer

Correct Answer:

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


Note: This Question is unanswered, help us to find answer for this one

45. Which of the following statements is true about the @RequestParam annotation?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

46.

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

Answer

Correct Answer:

<mvc:resources/>



Note: This Question is unanswered, help us to find answer for this one

47.

Which of the following statements is correct?

Answer

Correct Answer:

<mvc:resources> doesn't declare its own handler mapping.



Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: CustomAutowireConfigurer

Note: This Question is unanswered, help us to find answer for this one

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

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

50. Which of the following is the default bean scope in Spring MVC?

Answer

Correct Answer: singleton

Note: This Question is unanswered, help us to find answer for this one

51. How can an HTTP 404 status code be returned from a Spring MVC Controller?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

52. Which of the following statements is true about the HandlerInterceptor interface?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

53.

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

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

54.

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

Answer

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

55. Which of the following statements is true about the @RequestMapping annotation?

Answer

Correct Answer: It has a String[] paramater.
It supports ant-style paths.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

56.

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

Correct Answer:

p-namespace



Note: This Question is unanswered, help us to find answer for this one

57.

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

Answer

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

58.

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

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

59. Which of the following classes provides built-in pagination functionality in SpringMVC?

Answer

Correct Answer: PagedListHolder

Note: This Question is unanswered, help us to find answer for this one

60.

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

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

61. Which of the following statements is true about method arguments that have an @ModelAttribute annotation?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

62. Which of the following statements is true about the HandlerExceptionResolver class?

Answer

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

Note: This Question is unanswered, help us to find answer for this one

63.

Which of the following statements is false?

Answer

Correct Answer:

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



Note: This Question is unanswered, help us to find answer for this one

64. Select all authentication methods that are supported by Spring Security by default:

Answer

Correct Answer: Basic Authentication
Digest Access Authentication

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

65. Which of the following interfaces can be implemented to interact with a container's management of the bean lifecycle?

Answer

Correct Answer: InitializingBean
DisposableBean

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

66. Which of the following dependency injection (DI) methodologies are available in Spring MVC?

Answer

Correct Answer: Constructor-based dependency injection
Setter-based dependency injection

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

67. Which of the following are possible validation methods for user input in Spring MVC?

Answer

Correct Answer: Annotation validation
Programmatic validation

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

68.

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

Answer

Correct Answer:

String viewName



String viewName, Map<String,?> model



Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

69. Which of the following code samples will get the ServletContext inside an Interceptor?

Answer

Correct Answer: @Autowired ServletContext context;
request.getSession().getServletContext();

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

70.

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

Answer

Correct Answer:

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



Adding "final HttpServletResponse response" as a parameter, then setting the header "Cache-Control" to "all-cache".



Using a Handler Interceptor and using the "postHandle" method provided by it.



Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

search
Spring MVC Subjects