45+ Spring CCEE MCQ
45+ Spring CCEE MCQ
Sr.No
Project Name YouTube Link
11 Tour and Travel System Project version 3.0 https://youtu.be/Dm7nOdpasWg?si=P_Lh2gcOFhlyudug
12 Gym Management system Project https://youtu.be/J8_7Zrkg7ag?si=LcxV51ynfUB7OptX
13 Online Driving License system Project https://youtu.be/3yRzsMs8TLE?si=JRI_z4FDx4Gmt7fn
14 Online Flight Booking system Project https://youtu.be/m755rOwdk8U?si=HURvAY2VnizIyJlh
15 Employee management system project https://youtu.be/lD1iE3W_GRw?si=Y_jv1xV_BljhrD0H
16 Online student school or college portal https://youtu.be/4A25aEKfei0?si=RoVgZtxMk9TPdQvD
17 Online movie booking system project https://youtu.be/Lfjv_U74SC4?si=fiDvrhhrjb4KSlSm
18 Online Pizza Delivery system project https://youtu.be/Tp3izreZ458?si=8eWAOzA8SVdNwlyM
19 Online Crime Reporting system Project https://youtu.be/0UlzReSk9tQ?si=6vN0e70TVY1GOwPO
20 Online Children Adoption Project https://youtu.be/3T5HC2HKyT4?si=bntP78niYH802I7N
pg. 4 contact us on 8007592194 / 9284926333 www.codewitharrays.in
Spring MCQ and Answers Explained
Q#1. Which annotation is not used to inject dependencies into a Spring bean?
(a) @Inject
(b) @Bean
(c) @Autowired
(d) @Resource
9 4
21
59
Answer: (b) @Bean 07
Explanation: ‘@Autowired’, ‘Resource’, and ‘@Inject’ all are used to inject dependencies. They use
80
different implementations of post processor classes. They all behave almost identically. The
‘@Autowired’ and ‘@Inject’ annotation use the ‘AutowiredAnnotationBeanPostProcessor’ to inject
.in
dependencies.
ar
Q#3. Which of the following annotations is NOT used to specify that a class is a Spring bean?
(a) @Service
(b) @Qualifier
(c) @Component
9 4
(d) @Controller
21
59
07
Answer: (c) @Qualifier
80
Explanation: The @Qualifier annotation is used with @Autowired in the context of autowiring. All
.in
other options are the generic stereotype annotations that can be used to specify that the class is a
ys
Spring bean.
ra
ar
(b) It helps in testing the module by injecting the dependent Mock Objects.
Explanation: Dependency injection allows components to be loosely coupled, making them easier to
test and maintain. It helps in achieving better code reusability. You can go through the benefits of
dependency injection.
Q#5. Consider the below @Value annotation, which is written using SpEL (Spring Expression
Language):
Which is the shorter representation of the above annotation using Elvis operator?
4
(a) @Value("#{myBean.myProperty ?: null}")
9
21
59
(b) @Value("#{myBean.myProperty ? myBean.myProperty : 'default'}")
07
80
(c) @Value("#{myBean.myProperty ? null}")
.in
Explanation: Using the Elvis operator (?:) , we can shorten the ternary operator syntax for the case
above. It is used in the Groovy language and also available in SpEL.
co
Q#6. In Spring’s XML configuration file, which XML tag is used to define a bean?
(a) <component>
(b) <service>
(c) <bean>
(d) <dependency>
Explanation: In Spring XML configuration, the <bean> tag is used to define a bean. It specifies the
class or interface to be instantiated as a bean and provides additional configuration options.
9 4
21
(b) It configures the transaction management
59
07
(c) It specifies the automatic ordering of bean initialization
80
.in
Explanation: The @Autowired annotation marks a field, constructor, or setter method for automatic
de
Q#8. Which annotation is used to enable Spring’s aspect-oriented programming (AOP) support?
(a) @Aspect
(b) @AspectJ
(c) @EnableAop
(d) @EnableAspectJAutoProxy
9 4
21
(a) It specifies the order of bean initialization among multiple beans
59
(b) It marks a bean for automatic injection
07
80
(c) It resolves ambiguity when multiple beans of the same type are present
.in
ys
Answer: c) It resolves ambiguity when multiple beans of the same type are present
de
co
Explanation: The @Qualifier annotation is used to resolve ambiguity when multiple beans of the
same type are present.
Q#10. Which annotation is used to declare a class as a Spring bean in a Java based configuration
class?
(a) @Service
(b) @Bean
(c) @Component
(d) @Autowired
Explanation: In a Java based configuration class, we use the @Bean annotation to declare a method
that returns an instance of a bean. The method is invoked by Spring to create the bean and manage
its lifecycle.
Q#11. Which of the following tag is required to enable component scanning in Spring XML
configuration?
9 4
21
(a) <context:scan package="com.example" />
59
(b) <scan-components base-package="com.example" />
07
80
Explanation: In order to enable component scanning in Spring XML configuration, we use the
<component-scan> tag with the attribute “base-package” to specify the package(s) to scan for
annotated components.
Q#12. Which is the incorrect purpose of the @Value annotation in Spring?
Explanation: The @Value annotation is used in all purposed mentioned in options a, b, and c. It is not
used to inject dependencies as part of autowiring.
(a) @Transactional
9 4
21
(b) @EnableTransactionManagement
59
(c) @ConfigureTransaction
07
80
(d) @EnableTransactions
.in
ys
ra
ar
Explanation: Spring Transaction support is not enabled by default. For that reason, we use the
w
Transaction related support in Spring. It activates the infrastructure for declarative transaction
co
management in Spring. For complete details with examples, you may refer Spring Transaction
Annotations.
Q#14. How can you retrieve a bean from the Spring ApplicationContext using Java code?
Explanation: You can retrieve a bean from the Spring ApplicationContext using the getBean()
method. It takes the bean name or its class as a parameter.
Q#15. Which scope in Spring ensures that object exists between every request in an HTTP session?
(a) Singleton
9 4
21
(b) Prototype
59
07
(c) Request
80
.in
(d) Session
ys
ra
ar
ith
Explanation: In the Session scope, the object exists between every request in an HTTP session.
de
co
Q#16. How can you define property placeholders in Spring XML configuration?
Explanation: You can define property placeholders in Spring XML configuration using the <context:
property-placeholder> tag. It allows you to specify properties from external files or system
properties.
Q#17. In order to enable the Spring expression language (SpEL) in Spring beans, Which annotation
is used?
(a) @ExpressionLanguage
(b) @EnableSpEL
(c) @SpEL
9 4
21
(d) @Value
59
07
80
Explanation: The @Value annotation in Spring supports the Spring expression language (SpEL). It
ys
offers you to evaluate SpEL expressions and inject the result into a bean property.
ra
ar
Q#18. If you want to configure a bean for lazy initialization in Spring, how can you configure a bean
ith
to be initialized lazily?
w
de
co
Q#19. To be eligible for Spring’s event handling mechanism, which interface should a class
implement?
(a) EventListener
(b) ApplicationListener
(c) EventHandler
4
(d) EventSubscriber
9
21
59
07
Answer: (b) ApplicationListener
80
Q#20. How can you register an event listener in Spring XML configuration?
ra
ar
ith
Answer: (d) Using the <bean> tag with the ApplicationListener interface
Explanation: You can register an event listener in Spring XML configuration by defining a bean using
the <bean> tag and implementing the ApplicationListener interface in the class.
4
Explanation: To enable asynchronous method execution in Spring, you can use the @EnableAsync
9
21
annotation. It activates Spring’s support for executing methods asynchronously.
59
Q#22. What is the purpose of the @Qualifier annotation in Spring?
07
80
(c) It resolves ambiguity when multiple beans of the same type are present
w
de
Answer: (c) It resolves ambiguity when multiple beans of the same type are present
Q#23. How can you enable Spring’s support for method-level caching?
Explanation: To enable Spring’s support for method-level caching, you can use the @EnableCaching
annotation. It activates the caching facility in Spring.
Q#24. How can you define the order of bean initialization in Spring?
9 4
21
(a) Using the <order> tag
59
(b) Using the @Order annotation
07
80
Explanation: You can use the @Order annotation to define the order of bean initialization in Spring.
It allows you to assign a value to indicate the desired order of bean creation. To get complete details
of @Order annotation with examples, kindly go through ‘@Order Annotaion In Spring‘.
Q#25. Which is the correct option to enable Spring MVC in a Spring based application?
Explanation: To enable the support for Spring MVC, you can use the @EnableWebMvc annotation.
(a) @Scheduled
9 4
(b) @EnableScheduling
21
59
(c) @TaskScheduler
07
80
(d) @Scheduling
.in
ys
ra
ar
activates the scheduling facility and permits the use of the @Scheduled annotation.
de
co
Q#27. If you want to schedule a method to be executed at fixed intervals in Spring, Which
annotation will you use?
(a) @FixedRate
(b) @FixedDelay
(c) @Cron
(d) @FixedInterval
Explanation: If you want to schedule a method to be executed at fixed intervals, the @FixedRate
annotation should be your choice to use. It defines the interval between method invocations in
milliseconds.
4
(a) #{beanName.propertyName}
9
21
59
(b) ${beanName.propertyName}
07
80
(c) @beanName.propertyName
.in
ys
(d) %beanName.propertyName%
ra
ar
ith
Q#29. Which annotation is used to mark a method as an exception handling method in Spring
MVC?
(a) @ExceptionHandler
(b) @ExceptionHandling
(c) @HandleException
(d) @ExceptionResolver
Q#30. If you want to write global exception handling code that can be applied to multiple
controllers in Spring MVC, which annotation will you use?
9 4
21
(a) @GlobalExceptionHandling
59
(b) @GlobalExceptionHandler
07
80
(c) @ControllerAdvice
.in
ys
(d) @EnableGlobalExceptionHandling
ra
ar
ith
w
Explanation: To configure global exception handling in Spring MVC, you can use the
@ControllerAdvice annotation. It offers you to define global exception handling methods
throughout multiple controllers.
Q#31. In Spring JDBC, which method will you use to execute a SQL query that can map the results to
a Java object?
(a) executeQueryForObject()
(b) fetchObject()
(c) executeForObject()
(d) queryForObject()
Explanation: The queryForObject() method is used to execute a SQL query and map the results to a
Java object in Spring JDBC. It is generally used for retrieving a single result.
9 4
21
(b) It manages the application's database connections
59
07
(c) It handles incoming requests and delegates them to controllers
80
.in
Explanation: The DispatcherServlet handles incoming requests and delegates them to controllers for
de
processing.
co
Q#33. Which of the following is helpful in passing data from a controller method to a view in Spring
MVC?
Explanation: You can pass data from a controller method to a view in Spring MVC by adding model
attributes to the Model object.
Q#34. How can you enable cross-origin resource sharing (CORS) in Spring MVC?
9 4
21
(b) Using the <enable-cors> tag
59
07
(c) Using the @CrossOrigin annotation
80
.in
Explanation: You can use the @CrossOrigin annotation in order to enable cross-origin resource
de
sharing (CORS) in Spring MVC . It allows you to specify the allowed origins, headers, and methods
co
Q#35. Which of the following is used to hold the model data and view information in Spring MVC?
(a) ViewResolver
(b) Model
(c) ModelAttribute
(d) ModelAndView
Explanation: We use ModelAndView class to hold the model data and view information in Spring
MVC.
Q#36. Which of the following is an incorrect use of Http GET request in a Spring MVC application?
9 4
21
(b) @RequestMapping(value = "/emp/{id}", method = GET)
59
07
(c) @GetMapping(consumes = {"text/plain", "application/*"})
80
.in
(d) @GetMapping("/")
ys
ra
ar
ith
(a) @PreAuthorize
(b) @PostAuthorize
(c) @PreFilter
(d) @Secured
Answer: (d) @Secured
9 4
(c) Around advice
21
59
(d) After advice
07
80
.in
Explanation: The After advice is executed irrespective of the execution flow of the matched method.
ar
Whether the method is executed normally or any exception occurs after advice will be executed
ith
either way.
w
Explanation: In pointcut expressions, ( ) => indicates zero parameter or without parameter, whereas
(..) => indicates any number or type of parameters. To know more about pointcut, kindly go through
‘examples of pointcut expressions‘.
Q#40. In the context of Spring AOP, select the method which is the candidate for below Pointcut
Expression?
public * *(Invoice)
94
21
(c) public void updateInvoice(Invoice inv){….}
59
07
(d) public Invoice getInvoice(Integer id){….}
80
.in
ys
Q#41. Which one is the another way of writing below annotation in Spring Security?
w
de
@Secured(“ROLE_MANAGER”,”ROLE_ADMIN”)
co
(a) @PreAuthorize("ROLE_MANAGER","ROLE_ADMIN")
Q#42. Which is a correct cron expression in Spring Scheduling that executes a task every year on Feb
14th 9:00:00 PM, if given day(14th) is Sunday or Tuesday only?
(a) 0 0 9 2 14 1,3
(b) 0 0 9 2 14 SUN,TUE
9 4
(c) 0 0 21 14 2 SUN,TUE
21
59
(d) 0 0 9 14 2 1,3 07
80
.in
Explanation: Except option (c), all other options are incorrect in either month, or date, or days of
ar
week place.
ith
Q#43. As part of the cron expressions improvement in Spring 5.3, the below cron expression can
w
0 0 0 * * 0
(a) @monthly
(b) @weekly
(c) @yearly
(d) @midnight
Explanation: Spring now supports some macros, which represent commonly used sequences in order
to improve readability. Even we can use these macros rather than writing the six-digit values. For
more details, kindly go through ‘macros support in Spring Scheduling‘.
Q#44. Which is a correct cron expression in Spring Scheduling that executes a task every year to
wish happy birthday on 24th March.
9 4
21
(a) 0 0 0 3 24 *
59
(b) 0 0 24 3 0 *
07
80
(c) 0 0 0 24 3 *
.in
ys
(d) 0 0 0 24 3 0
ra
ar
ith
w
Answer: (c) 0 0 0 24 3 *
de
co
Explanation: Except option (c), all other options are incorrect in either month, or date, or year place.
Q#45. In Spring JDBC, what does the NamedParameterJdbcTemplate class offer?
Answer: (b) Support for executing SQL statements with named parameters
Explanation: The NamedParameterJdbcTemplate class in Spring JDBC offers support for executing
SQL statements with named parameters. It allows you to specify parameters by name instead of their
positional index.
9 4
21
59
07
80
.in
ys
ra
ar
ith
w
de
co
https://www.youtube.com/@codewitharrays
https://www.instagram.com/codewitharrays/
https://codewitharrays.in/project