TCS T4 Spring Boot2
TCS T4 Spring Boot2
1. What command is used to create a new Spring Boot project from the command line?
o A. spring init
o B. mvn spring-boot:run
o C. gradle spring-boot
o D. spring create
o A. Jetty
o B. Undertow
o C. WebLogic
o D. Tomcat
Answer: D. Tomcat
3. How can you disable the default web environment in a Spring Boot application?
o A. server.disable=true
o B. spring.main.web-application-type=none
o C. spring.server.disable=true
o D. server.stop=true
Answer: B. spring.main.web-application-type=none
4. Which starter would you use for Spring Boot and JPA integration?
o A. spring-boot-starter-data-jpa
o B. spring-boot-starter-jpa
o C. spring-boot-data-jpa
o D. spring-boot-starter-sql
Answer: A. spring-boot-starter-data-jpa
5. What annotation is used to run unit tests with the full Spring ApplicationContext?
o A. @RunWith(SpringJUnit4ClassRunner.class)
o B. @Test
o C. @SpringBootTest
o D. @Autowired
Answer: C. @SpringBootTest
6. Which file is used to customize application configuration in Spring Boot?
o A. application.properties or application.yml
o B. config.properties
o C. bootstrap.properties
o D. settings.xml
o A. spring.config=dev
o B. spring.profiles.active=dev
o C. server.profile=dev
o D. application.profile=dev
Answer: B. spring.profiles.active=dev
8. To make a Spring Boot application exit with a specific code, which interface should be
implemented?
o A. CommandLineRunner
o B. ExitCodeGenerator
o C. ExitCodeApplication
o D. ExitApplication
Answer: B. ExitCodeGenerator
10. In Spring Boot, which property is used to set the default server port to 8081?
o A. server.port=8081
o B. port=8081
o C. application.port=8081
o D. spring.port=8081
Answer: A. server.port=8081
o B. @Id
o C. @Key
o D. @GeneratedValue
Answer: B. @Id
12. What is the purpose of the @Query annotation in Spring Data JPA?
11. Which file is typically used to configure application-level properties in Spring Boot?
o A. application.yml
o B. application.conf
o C. config.xml
o D. settings.json
Answer: A. application.yml
12. What is the purpose of the @ComponentScan annotation in a Spring Boot application?
13. How can a Spring Boot application be packaged as an executable JAR file?
o D. Both B and C
15. In a Spring Boot application, where are custom configurations for development and production
environments typically defined?
o A. application.properties
o C. application-custom.xml
o D. application-db.yml
16. Which annotation in Spring Boot is used to mark a method as one that should execute once at
application startup?
o A. @PostConstruct
o B. @RunOnStartup
o C. @ApplicationStartup
o D. @EnableStartup
Answer: A. @PostConstruct
17. Which of the following commands is used to run a Spring Boot application using Maven?
o A. mvn spring:start
o B. mvn spring-boot:run
o C. mvn run:app
o D. mvn spring:bootRun
18. Which annotation is used to inject values from application.properties or application.yml files in
Spring Boot?
o A. @ConfigValue
o B. @Value
o C. @Inject
o D. @InjectValue
Answer: B. @Value
19. How does Spring Boot support configuration properties inheritance in YAML files?
20. Which annotation in Spring Boot applications denotes a command-line runner that executes upon
application startup?
o A. @ApplicationRunner
o B. @CommandLineRunner
o C. @StartupRunner
o D. @Runner
Answer: B. @CommandLineRunner
21. Which annotation would you use to define a path variable in Spring Boot?
o A. @RequestParam
o B. @RequestPath
o C. @PathVariable
o D. @Variable
Answer: C. @PathVariable
22. How do you define a response status in a Spring Boot REST controller method?
o A. @Status
o B. @ResponseCode
o C. @HttpStatus
o D. @ResponseStatus
Answer: D. @ResponseStatus
23. Which HTTP status code is usually returned when no content is available to send for a request?
o A. 200 OK
o B. 201 Created
o D. 204 No Content
o A. GET
o B. POST
o C. PUT
o D. PATCH
Answer: D. PATCH
...
Microservices - 10 Questions
o C. Rate limiting
o D. Inter-service authentication
32. In Spring Boot microservices, what is the main role of an API Gateway?
o C. To provide caching
33. Which pattern in microservices helps prevent cascading failures by providing a fallback method?
o A. Retry
o B. Circuit Breaker
o C. API Gateway
o D. Load Balancer
...
41. Which of the following annotations is used to initialize a Spring Boot test with the full context?
o A. @TestContext
o B. @SpringBootTest
o C. @ContextTest
o D. @ServiceTest
Answer: B. @SpringBootTest
43. In Spring Boot testing, which class is typically used to test controllers by simulating HTTP requests?
o A. TestHttpClient
o B. MockMvc
o C. HttpSimulator
o D. HttpRequestTest
Answer: B. MockMvc
...
o C. To store controllers
52. How does Spring Data JPA automatically implement common database operations like findAll and
save?
o B. By adding @ActuatorExpose
o C. By enabling expose: true in YAML
o A. Implement ErrorPageConfigurer
o A. @EnableAsync
o B. @Async
o C. @EnableAsynchronous
o D. @AsyncProcessing
Answer: A. @EnableAsync
o B. Remote debugging
o A. 8081
o B. 9090
o C. 8000
6. In Spring Boot, which starter dependency is added to include logging with SLF4J and Logback?
o A. spring-boot-starter-logging
o B. spring-boot-starter-logback
o C. spring-boot-starter-slf4j
o D. spring-boot-logger
Answer: A. spring-boot-starter-logging
7. To automatically restart a Spring Boot application on file changes, which module should you
include?
o A. spring-boot-starter-devtools
o B. spring-boot-starter-reload
o C. spring-boot-restart
o D. spring-boot-filewatcher
Answer: A. spring-boot-starter-devtools
o A. ssl.enable=true in application.properties
o A. @Configurable
o B. @Configuration
o C. @Config
o D. @SpringBootConfig
Answer: B. @Configuration
o A. XML configuration
o C. JNDI lookup
o A. Distributed logging
o B. API Gateway
o C. Service registry
o D. Security features
o A. Eureka
o B. Ribbon
o C. Config Server
o D. Circuit Breaker
13. What pattern helps microservices tolerate network issues by retrying failed requests?
o A. Rate limiting
o B. Circuit Breaker
o C. Bulkhead
o D. Retry pattern
o B. Load balancing
o D. Distributed transactions
15. Which property enables client-side load balancing with Spring Cloud Ribbon?
o A. ribbon.loadBalancer.enabled=true
o B. ribbon.client.enabled=true
o C. client.loadbalancer.active=true
o D. load.balancer.enabled=true
Answer: A. ribbon.loadBalancer.enabled=true
...
o A. @Secure
o B. @EnableMethodSecurity
o C. @EnableSecurity
o D. @Secured
Answer: B. @EnableMethodSecurity
22. What is the purpose of the @PreAuthorize annotation in Spring Security?
23. Which component in Spring Security is responsible for handling login attempts?
o A. UserDetailsService
o B. AuthenticationProvider
o C. LoginFilter
o D. AuthenticationManager
Answer: D. AuthenticationManager
o A. UserAuthService
o B. CustomUserDetailsService
o C. CustomAuthenticationManager
o D. AuthenticationService
Answer: B. CustomUserDetailsService
o A. To decode passwords
...
31. Which annotation is used in Spring Boot to mock beans within the application context?
o A. @Mock
o B. @AutowiredMock
o C. @MockBean
o D. @MockedComponent
Answer: C. @MockBean
32. Which Spring Boot test utility is specifically used to test HTTP endpoints?
o A. WebClientTest
o B. MockHttpServletRequest
o C. MockHttpTest
o D. MockMvc
Answer: D. MockMvc
o A. getRequest()
o B. performGet()
o C. sendGet()
o D. perform(MockMvcRequestBuilders.get())
Answer: D. perform(MockMvcRequestBuilders.get())
35. What annotation enables the creation of a temporary database during tests?
o A. @TemporaryDatabase
o B. @H2Database
o C. @AutoConfigureTestDatabase
o D. @AutoDatabase
Answer: C. @AutoConfigureTestDatabase
...
41. What does the @Modifying annotation indicate in Spring Data JPA?
o C. A method is paginated
o D. A method is transactional
43. Which annotation specifies a native SQL query in Spring Data JPA?
o A. @SQL
o B. @NativeQuery
o C. @NativeQuerySQL
o D. @Query
Answer: D. @Query
1. Which annotation is used to specify the main configuration class in a Spring Boot application?
o A. @SpringBootApp
o B. @SpringApplication
o C. @SpringBootConfiguration
o D. @SpringBootApplication
Answer: D. @SpringBootApplication
o A. Disables auto-configuration
o A. @ComponentScan
o B. @ScanComponents
o C. @EnableComponents
o D. @Component
Answer: A. @ComponentScan
5. In Spring Boot, which property is used to set the default server port in application.properties?
o A. spring.port
o B. server.port
o C. spring.boot.port
o D. server.defaultPort
Answer: B. server.port
o A. @DAO
o B. @Repository
o C. @Service
o D. @DataRepository
Answer: B. @Repository
o A. spring-boot:run -Dspring.profiles.active=customProfile
o D. boot.run --profile=customProfile
8. Which annotation is used to handle exceptions at the controller level in Spring Boot?
o A. @HandleException
o B. @ControllerAdvice
o C. @ExceptionController
o D. @ExceptionHandler
Answer: D. @ExceptionHandler
o A. @ExcludeComponent
o B. @ComponentIgnore
o C. @ComponentScan(excludeFilters)
o D. @ExcludeFilter
Answer: C. @ComponentScan(excludeFilters)
o B. @EnableScheduling
o C. @Scheduled
o D. @TaskScheduler
Answer: B. @EnableScheduling
o A. Database management
o B. Load balancing
o C. Service registry
o D. Security management
12. Which property is used to specify the Eureka server URL in the client configuration?
o A. eureka.server.url
o B. eureka.instance.url
o C. eureka.client.service-url.defaultZone
o D. eureka.client.service.defaultZone
Answer: C. eureka.client.service-url.defaultZone
o A. Feign
o B. Ribbon
o C. Config Server
o D. Zuul
Answer: B. Ribbon
o A. Service registration
o B. Load balancing
o D. API Gateway
15. How can you enable the circuit breaker in Spring Cloud?
o A. @EnableCircuitBreaker
o B. @CircuitBreaker
o C. @EnableHystrix
o D. @EnableResilience
Answer: A. @EnableCircuitBreaker
o A. Load balancing
o B. Service discovery
o D. Distributed logging
o A. @Feign
o B. @FeignClient
o C. @FeignService
o D. @FeignController
Answer: B. @FeignClient
18. In a Spring Cloud Config Server, which configuration repository can you use?
o A. Git repository
o C. SVN repository
o A. Zipkin
o B. Eureka
o C. Hystrix
o D. Config Server
Answer: A. Zipkin
20. Which library provides service discovery for Spring Cloud applications?
o A. Hystrix
o B. Ribbon
o C. Eureka
o D. Zuul
Answer: C. Eureka
21. What is the purpose of the @Id annotation in a Spring Data JPA entity?
o A. @EnableCache
o B. @EnableCaching
o C. @Cache
o D. @Cacheable
Answer: B. @EnableCaching
23. Which annotation is used to specify a custom query in Spring Data JPA?
o A. @SQL
o B. @JpaQuery
o C. @CustomQuery
o D. @Query
Answer: D. @Query
24. What does the @OneToMany annotation specify in Spring Data JPA?
o A. One-to-one relationship
o B. One-to-many relationship
o C. Many-to-many relationship
o D. Many-to-one relationship
25. How can you define a primary key strategy in Spring Data JPA?
o A. @PrimaryKey
o B. @GeneratedValue(strategy=…)
o C. @PrimaryKeyGenerated
o D. @KeyStrategy
Answer: B. @GeneratedValue(strategy=…)
26. Which of the following is NOT a valid cascade type in JPA?
o A. MERGE
o B. UPDATE
o C. PERSIST
o D. DETACH
Answer: B. UPDATE
o A. Many-to-many
o B. Many-to-one
o C. One-to-one
o D. One-to-many
Answer: B. Many-to-one
29. Which annotation is used to specify the name of a database table in an entity class?
o A. @TableName
o B. @EntityTable
o C. @Table
o D. @DatabaseTable
Answer: C. @Table
o A. @Unique
o B. @UniqueConstraint
o C. @Column(unique=true)
o D. @Table(uniqueConstraints=…)
Answer: D. @Table(uniqueConstraints=…)
1. In Spring Boot, which of these configurations is typically used for unit tests?
o A. @RunWith
o B. @TestConfiguration
o C. @MockBean
o D. @TestProperty
Answer: B. @TestConfiguration
o A. Logback
o B. Log4j
o C. JUL
o D. SLF4J
Answer: A. Logback
o D. Enables monitoring
o A. 400
o B. 401
o C. 409
o D. 500
Answer: C. 409
6. Which annotation is used to specify a controller advice for handling exceptions globally?
o A. @GlobalExceptionHandler
o B. @ControllerAdvice
o C. @RestControllerAdvice
o D. @ExceptionHandler
Answer: B. @ControllerAdvice
7. What is the default thread pool size for asynchronous tasks in Spring Boot?
o A. 4
o B. 5
o C. 8
o D. 10
Answer: D. 10
o A. spring.async.enabled
o B. spring.task.execution.pool.enabled
o C. task.async.enable
o D. @EnableAsync
Answer: D. @EnableAsync
9. In Spring Boot, which annotation do you use for scheduling a method to run periodically?
o A. @Scheduled
o B. @Cron
o C. @EnableScheduling
o D. @EnableTaskScheduler
Answer: A. @Scheduled
o A. logging.level
o B. log.level
o C. logger.level
o D. logging.debug.level
Answer: A. logging.level
11. What is the default fetch type for @OneToMany relationships in JPA?
o A. EAGER
o B. LAZY
o C. IMMEDIATE
o D. DYNAMIC
Answer: B. LAZY
o D. Generates custom ID
o A. @Filter
o B. @FilterChain
o C. @FilterDef
o D. @Filters
Answer: D. @Filters
14. In Spring Data JPA, what method can you use to save a list of entities?
o A. saveBatch
o B. saveAll
o C. insertList
o D. persistAll
Answer: B. saveAll
17. In a JPA repository, which method retrieves the first entity matching a condition?
o A. findOne
o B. findTopBy
o C. findFirstBy
o D. findUniqueBy
Answer: C. findFirstBy
o A. @CompositeKey
o B. @EmbeddedId
o C. @PrimaryKeyClass
o D. @MultiKey
Answer: B. @EmbeddedId
o A. spring.sql.show
o B. spring.jpa.show-sql
o C. spring.jpa.sql-enabled
o D. sql.display
Answer: B. spring.jpa.show-sql
20. In Spring Data JPA, what method deletes all records of a particular entity?
o A. deleteAll
o B. removeAll
o C. deleteRecords
o D. removeEntities
Answer: A. deleteAll
21. Which filter is applied first in the Spring Security filter chain by default?
o A. AuthenticationFilter
o B. UsernamePasswordAuthenticationFilter
o C. SecurityContextPersistenceFilter
o D. LogoutFilter
Answer: C. SecurityContextPersistenceFilter
22. How can you specify which endpoints to secure in Spring Security?
o A. @ControllerSecurity
o B. @SecurityEnabled
o C. HttpSecurity
o D. EndpointSecurity
Answer: C. HttpSecurity
23. Which annotation is used to disable security for specific methods in Spring?
o A. @AllowAll
o B. @Unsecured
o C. @PermitAll
o D. @AllowUnsecured
Answer: C. @PermitAll
o A. @EnableWebSecurity
o B. @EnableGlobalMethodSecurity
o C. @EnableSecurity
o D. @SecurityConfig
Answer: B. @EnableGlobalMethodSecurity
o A. @AllowRoles
o B. @Secured
o C. @RoleAllowed
o D. @PermitRoles
Answer: B. @Secured
o A. setAuthorities
o B. grantRoles
o C. setRoles
o D. authorizeRoles
Answer: A. setAuthorities
27. Which annotation is used to secure REST APIs using Spring Security?
o A. @SecuredREST
o B. @RestSecure
o C. @RestController
o D. @PreAuthorize
Answer: D. @PreAuthorize
o A. http.setCustomLogin
o B. http.formLogin().loginPage()
o C. http.loginCustom()
o D. http.customLoginPage()
Answer: B. http.formLogin().loginPage()
o A. GET
o B. PATCH
o C. TRACE
o D. CONNECT
Answer: D. CONNECT
o C. Database layer
o D. Security configurations
o A. @TestParams
o B. @ParameterizedTest
o C. @TestParameterized
o D. @ParamsTest
Answer: B. @ParameterizedTest
33. Which tool is commonly used for Spring Boot integration testing?
o A. JUnit
o B. Mockito
o C. RestAssured
o D. DBUnit
Answer: C. RestAssured
o A. Constructor Injection
o B. Method Injection
o C. Field Injection
3. Which annotation is used to inject a bean in a Spring class using constructor-based dependency
injection?
o A. @Inject
o B. @Autowired
o C. @ConstructorInject
o D. @Autowired(required=false)
Answer: B. @Autowired
o A. @Bean
o B. @Component
o C. @Service
5. In Spring, what happens if there is more than one bean of the same type and you use @Autowired?
o A. @Entity
o B. @Controller
o C. @Component
o D. @Service
Answer: C. @Component
o A. Singleton
o B. Prototype
o C. Request
o D. Session
Answer: A. Singleton
o A. @Autowired
o B. @Bean
o C. @Component
o D. @Inject
Answer: A. @Autowired
o A. @Autowired
o B. @Primary
o C. @Qualifier
o D. @Bean
Answer: C. @Qualifier
Spring Task Scheduler and Cron Jobs (50 Questions)
o A. @TaskScheduler
o B. @Scheduled
o C. @EnableScheduling
o D. @Cron
Answer: B. @Scheduled
12. How can you specify the cron expression for scheduling tasks in Spring?
o D. @Scheduled(cron="*/10 * * * * ?")
13. Which of the following annotations enables task scheduling in Spring Boot?
o A. @Scheduled
o B. @EnableScheduling
o C. @EnableTaskScheduling
o D. @EnableCron
Answer: B. @EnableScheduling
14. What is the default fixed rate for scheduling tasks in Spring Boot?
o A. 1 second
o B. 5 seconds
o C. 10 seconds
o D. 60 seconds
Answer: A. 1 second
16. What is the cron expression used to run a task every day at 2 AM?
o A. 0 2 * * *
o B. 0 2 1 * * ?
o C. 0 0 2 * * ?
o D. 0 0 1 2 * ?
Answer: C. 0 0 2 * * ?
o A. */5 * * * *
o B. 5 5 5 5 5
o C. */2 * * *
o D. * * * * * *
Answer: A. */5 * * * *
18. Which of the following is true about the @Scheduled(fixedDelay = 1000) annotation?
o A. The task runs every 1 second regardless of the completion time of the previous task
o B. The task runs 1 second after the completion of the previous task
o C. The task runs every 1 second but does not wait for the previous task to finish
o D. The task runs every 1 second and blocks the next execution
Answer: B. The task runs 1 second after the completion of the previous task
21. Which of the following is used to configure Spring Security for form-based login?
o A. http.formLogin().loginPage("/login")
o B. http.authenticationForm().loginPage("/login")
o C. http.enableLogin().loginPage("/login")
o D. http.formLogin().loginUrl("/login")
Answer: A. http.formLogin().loginPage("/login")
22. Which of the following is the correct order for Spring Security filters?
o A. @RolesAllowed
o B. @Secured
o C. @PreAuthorize
o D. @AllowRoles
Answer: B. @Secured
o A. ROLE_
o B. USER_
o C. ADMIN_
o D. SECURITY_
Answer: A. ROLE_
28. Which of the following is used for JWT (JSON Web Token) authentication in Spring Security?
o A. JwtAuthenticationFilter
o B. JWTAuthorizationFilter
o C. OAuth2AuthenticationFilter
o D. JwtTokenProvider
Answer: A. JwtAuthenticationFilter
29. Which annotation is used for securing HTTP requests in Spring Security?
o A. @Secured
o B. @PreAuthorize
o C. @EnableWebSecurity
o D. @SecurityConfig
Answer: C. @EnableWebSecurity
30. Which of the following is true about @Secured annotation in Spring Security?
o A. @EventHandler
o B. @Subscribe
o C. @EventListener
o D. @Listener
Answer: C. @EventListener
o A. To listen to events
o A. event.publish()
o B. applicationContext.publishEvent()
o C. applicationContext.getEventPublisher()
o D. applicationEventListener.publish()
Answer: B. applicationContext.publishEvent()
34. What is the default event type for Spring's application events?
o A. ApplicationStartedEvent
o B. ApplicationContextEvent
o C. ContextRefreshedEvent
o D. ApplicationEvent
Answer: D. ApplicationEvent
35. How do you specify the type of event to listen for in a Spring event listener?
o D. By extending ApplicationListener
Dependency Injection
o A. Tight coupling
o B. Loose coupling
o C. Inversion of Control
o D. Dependency inversion
o Answer: C
2. Which of the following is NOT a type of dependency injection?
o A. Constructor injection
o B. Setter injection
o C. Field injection
o D. Method injection
o Answer: D
o Answer: B
o Answer: C
5. What is the correct cron expression to run a task every Monday at 9 AM?
o A. 0 0 9 * * MON
o B. 0 9 * * MON
o C. 9 0 * * MON
o D. MON 9 0 * *
o Answer: A
o Answer: A
o B. @PreAuthorize
o C. @PostAuthorize
o Answer: D
o Answer: C
o Answer: B
Spring Messaging
o Answer: A
o A. Message Channel
o B. Message Transformer
o C. Message Filter
o D. Message Queue
o Answer: D
o Answer: A
Spring MVC
o Answer: A
14. Which of the following is NOT a common HTTP method supported by Spring MVC?
o A. GET
o B. POST
o C. PUT
o D. DELETE
o Answer: D
Spring Data
• Answer: A
• A. @Repository
• B. @JpaRepository
• C. @JpaEntity
• D. @Transactional
• Answer: B
Spring Security
• Answer: A
• A. Basic Authentication
• B. Form-Based Authentication
• C. OAuth2
• Answer: D
• Answer: A
Spring Boot
• Answer: A
21. Which Spring Boot starter POM is used for web applications?
• A. spring-boot-starter-web
• B. spring-boot-starter-data-jpa
• C. spring-boot-starter-security
• D. spring-boot-starter-test
• Answer: A
Spring AOP
• Answer: B
• A. @Aspect
• B. @Component
• C. @Service
• D. @Controller
• Answer: A
Spring Cloud
• Answer: A
• Answer: B
Spring Batch
• Answer: A
• B. Job Launcher
• C. Step
• Answer: D
Spring JMS
• Answer: A
• A
generate more
Show drafts
Spring Data
30. What is the purpose of the @Query annotation in Spring Data JPA?
• C. To enable pagination
• D. To enable sorting
• Answer: A
31. What is the purpose of the @Transactional annotation in Spring Data JPA?
• C. To enable pagination
• D. To enable sorting
• Answer: A
Spring Security
• B. To authenticate users
• D. To encrypt passwords
• Answer: A
• D. To encrypt passwords
• Answer: A
Spring Boot
• Answer: D
• B. To define beans
• C. To define controllers
• D. To define services
• Answer: A
Spring AOP
• Answer: A
• Answer: B
Spring Cloud
• Answer: A
• Answer: D
Spring Batch
• Answer: A
• Answer: A
Spring JMS
• Answer: A
44. What is the purpose of the @EnableJpaRepositories annotation in Spring Data JPA?
• Answer: D
45. What is the purpose of the @Transactional annotation in Spring Data JPA repositories?
• C. To enable pagination
• D. To enable sorting
• Answer: A
Spring Security
• B. To authenticate users
• Answer: A
• B. To authenticate users
• D. To encrypt passwords
• Answer: A
Spring Boot
• Answer: A
• Answer: A
Spring AOP
• Answer: C
o A. HTTP
o B. AMQP
o C. WebSockets
o D. Both B and C
38. Which Spring module is used for working with messaging and queues?
o A. Spring JMS
o B. Spring Data
o C. Spring Web
o D. Spring Integration
o A. RabbitMQ
o B. ActiveMQ
o C. SimpleMessageBroker
o D. JmsTemplate
Answer: C. SimpleMessageBroker
41. Which of the following is used to send a message to a destination in Spring Messaging?
o A. @SendTo
o B. @MessageSend
o C. @MessageDestination
o D. @SendMessage
Answer: A. @SendTo
42. Which interface in Spring Messaging provides the functionality for sending and receiving messages?
o A. MessageChannel
o B. MessageQueue
o C. JmsTemplate
o D. WebSocketHandler
Answer: A. MessageChannel
43. What is the default configuration for a message broker in Spring WebSocket?
o A. Stomp
o B. RabbitMQ
o C. JMS
o D. AMQP
Answer: A. Stomp
o A. @MessageListener
o B. @ReceiveMessage
o C. @MessageMapping
o D. @Listen
Answer: C. @MessageMapping
45. Which of the following is true about the Spring Integration module?
o A. They are used to add dependencies for specific functionalities to your project
Answer: A. They are used to add dependencies for specific functionalities to your project
47. Which of the following is a commonly used Spring Boot starter for web applications?
o A. spring-boot-starter-web
o B. spring-boot-starter-messaging
o C. spring-boot-starter-data-jpa
o D. spring-boot-starter-thymeleaf
Answer: A. spring-boot-starter-web
48. Which Spring Boot starter is used to include support for embedded Tomcat server?
o A. spring-boot-starter-logging
o B. spring-boot-starter-tomcat
o C. spring-boot-starter-web
o D. spring-boot-starter-jetty
Answer: B. spring-boot-starter-tomcat
49. Which Spring Boot starter is used to add support for database connectivity?
o A. spring-boot-starter-data-jpa
o B. spring-boot-starter-web
o C. spring-boot-starter-thymeleaf
o D. spring-boot-starter-logging
Answer: A. spring-boot-starter-data-jpa
50. Which of the following starters is used for adding support for Spring Security?
o A. spring-boot-starter-security
o B. spring-boot-starter-data
o C. spring-boot-starter-actuator
o D. spring-boot-starter-web
Answer: A. spring-boot-starter-security
52. Which Spring Boot starter is used for building RESTful web services?
o A. spring-boot-starter-web
o B. spring-boot-starter-rest
o C. spring-boot-starter-jms
o D. spring-boot-starter-messaging
Answer: A. spring-boot-starter-web
o C. WebSocket configurations
54. Which Spring Boot starter would you use for integrating Spring Boot with Elasticsearch?
o A. spring-boot-starter-data-elasticsearch
o B. spring-boot-starter-web
o C. spring-boot-starter-data-mongodb
o D. spring-boot-starter-thymeleaf
Answer: A. spring-boot-starter-data-elasticsearch
o A. spring-boot-starter-actuator
o B. spring-boot-starter-web
o C. spring-boot-starter-security
o D. spring-boot-starter-data-jpa
Answer: A. spring-boot-starter-actuator
57. Which of the following annotations is used to mark a class as a Spring MVC controller?
o A. @Controller
o B. @Service
o C. @RestController
o D. @Bean
Answer: A. @Controller
58. Which of the following annotations is used to define a RESTful controller in Spring MVC?
o A. @RestController
o B. @Controller
o C. @Service
o D. @Component
Answer: A. @RestController
60. Which of the following methods in a Spring controller is used to handle HTTP GET requests?
o A. @RequestMapping(method = RequestMethod.GET)
o B. @PostMapping
o C. @GetMapping
o D. @PutMapping
Answer: C. @GetMapping
62. In Spring MVC, which annotation is used to specify a path variable in a URL?
o A. @RequestParam
o B. @PathVariable
o C. @RequestMapping
o D. @RequestBody
Answer: B. @PathVariable
o A. InternalResourceViewResolver
o B. ThymeleafViewResolver
o C. JSPViewResolver
o D. FreeMarkerViewResolver
Answer: A. InternalResourceViewResolver
o A. @RequestMapping
o B. @PostMapping
o C. @GetMapping
o D. @SubmitMapping
Answer: B. @PostMapping
65. Which of the following is the default scope for Spring beans?
• A. Singleton
• B. Prototype
• C. Request
• D. Session
Answer: A. Singleton
67. Which of the following annotations is used to declare a Spring bean in a class?
• A. @Bean
• B. @Component
• C. @Controller
• D. @Service
Answer: B. @Component
• A. @Inject
• B. @Autowired
• C. @InjectDependencies
• D. @AutowiredBean
Answer: B. @Autowired
Answer: B. It specifies which bean to inject when multiple beans are available
• A. Constructor Injection
• B. Setter Injection
• C. Field Injection
• A. @Autowired
• B. @Inject
• C. @Bean
• D. @AutowiredConstructor
Answer: A. @Autowired
• A. Marks the bean as the default bean when multiple candidates exist
Answer: A. Marks the bean as the default bean when multiple candidates exist
73. What is the main difference between @Autowired and @Inject in Spring?
• C. @Autowired is used for constructor injection, while @Inject is used for setter injection
• D. @Autowired supports optional injection, while @Inject does not
74. Which of the following is NOT a valid type of Spring bean scope?
• A. Singleton
• B. Prototype
• C. Application
• D. Request
Answer: C. Application
• A. An exception is thrown
• A. @EnableScheduling
• B. @EnableTasks
• C. @ScheduledTasks
• D. @TaskScheduling
Answer: A. @EnableScheduling
78. Which of the following cron expression represents the task to run every day at midnight in Spring?
• A. 0 0 12 * * ?
• B. 0 0 0 * * ?
• C. 0 0 23 * * ?
• D. 0 0 0 1 * ?
Answer: B. 0 0 0 * * ?
• A. schedule()
• B. runTask()
• C. scheduleAtFixedRate()
• D. scheduleTask()
Answer: A. schedule()
80. Which of the following is a valid cron expression format used in Spring’s @Scheduled annotation?
• A. * * * * *
81. What does the fixedRate attribute in the @Scheduled annotation do?
• B. Executes the task after a fixed interval from the last task's start time
• C. Specifies a fixed delay between the completion of one execution and the start of the next
Answer: B. Executes the task after a fixed interval from the last task's start time
82. What is the purpose of the fixedDelay attribute in the @Scheduled annotation?
• A. It specifies the delay between the start of one execution and the start of the next
Answer: A. It specifies the delay between the start of one execution and the start of the next
83. Which of the following is a valid cron expression to run a task every hour?
• A. 0 0 * * * ?
• B. 0 * * * * ?
• C. * 0 * * * ?
• D. 0 0 0 * * ?
Answer: A. 0 0 * * * ?
84. Which interface does Spring use for task scheduling?
• A. TaskExecutor
• B. TaskScheduler
• C. Runnable
• D. ScheduledExecutorService
Answer: B. TaskScheduler
85. Which of the following annotations is used to enable the Spring scheduling functionality for cron
jobs?
• A. @EnableScheduling
• B. @ScheduledTasks
• C. @CronEnabled
• D. @TaskScheduling
Answer: A. @EnableScheduling
86. Which Spring Security annotation is used to specify a method should be accessible only by
authenticated users?
• A. @Secured
• B. @PreAuthorize
• C. @PostAuthorize
• D. @Authenticate
Answer: A. @Secured
87. In Spring Security, what is the default role for authenticated users?
• A. ROLE_USER
• B. ROLE_ADMIN
• C. ROLE_GUEST
• D. ROLE_AUTHENTICATED
Answer: A. ROLE_USER
• A. AuthenticationManager
• B. SecurityContextHolder
• C. AuthenticationProvider
• D. SecurityManager
Answer: A. AuthenticationManager
89. Which annotation in Spring Security is used to restrict access to a method to a specific role?
• A. @PreAuthorize
• B. @Secured
• C. @RolesAllowed
• D. @PermitAll
Answer: B. @Secured
90. Which interface is used by Spring Security to retrieve user details for authentication?
• A. UserDetailsService
• B. AuthenticationProvider
• C. UserService
• D. UserRepository
Answer: A. UserDetailsService
92. Which Spring Security feature allows the user to authenticate using JWT (JSON Web Token)?
• A. HttpSecurity
• B. JwtAuthenticationFilter
• C. JWTTokenFilter
• D. OAuth2Login
Answer: B. JwtAuthenticationFilter
94. Which class in Spring Security manages the user session for an HTTP request?
• A. SecurityContextHolder
• B. HttpSessionSecurityContextRepository
• C. AuthenticationManager
• D. SessionManager
Answer: B. HttpSessionSecurityContextRepository
Spring Data
• Answer: D
Spring Security
• Answer: A
Spring Boot
• Answer: D
Spring AOP
Spring Cloud
• Answer: A
1. What is the correct way to inject a dependency in Spring using annotation-based configuration?
o A. @Inject
o B. @Autowired
o C. @InjectBean
o D. @Dependency
Answer: B. @Autowired
2. Which annotation can be used to create a Spring bean that will be automatically injected into other
classes?
o A. @Component
o B. @Bean
o C. @Service
o D. @Repository
Answer: A. @Component
o A. @ComponentScan
o B. @Configuration
o C. @Bean
o D. @Repository
Answer: C. @Bean
4. Which of the following methods is used for dependency injection via constructor in Spring?
o C. Both A and B
o D. Neither A nor B
Answer: C. Both A and B
o A. @Scheduled
o B. @TaskScheduled
o C. @CronTask
o D. @Task
Answer: A. @Scheduled
6. Which of the following cron expressions would run a task every day at midnight?
o A. 0 0 12 * * *
o B. 0 0 0 * * *
o C. 0 0 0 1 * *
o D. 0 0 12 * * *
Answer: B. 0 0 0 * * *
7. What is the default cron expression for @Scheduled(cron = "") if not specified?
o A. @EnableScheduling
o B. @TaskScheduler
o C. @ScheduledTask
o D. @ScheduledTasks
Answer: A. @EnableScheduling
o A. AuthenticationManager
o B. UserDetailsService
o C. SecurityContextHolder
o D. AuthorizationManager
Answer: B. UserDetailsService
o A. @Secure
o B. @PreAuthorize
o C. @Authorize
o D. @AccessControl
Answer: B. @PreAuthorize
11. Which method in Spring Security’s HttpSecurity class is used to configure form-based login?
o A. http.formLogin()
o B. http.loginForm()
o C. http.formAuthentication()
o D. http.setLoginForm()
Answer: A. http.formLogin()
12. In Spring Security, which class is used to authenticate the current user via JWT token?
o A. JwtAuthenticationFilter
o B. UsernamePasswordAuthenticationFilter
o C. SecurityContextFilter
o D. JwtAuthenticationManager
Answer: A. JwtAuthenticationFilter
o A. @EventPublisher
o B. @PublishEvent
o C. @EventListener
o D. @TransactionalEventListener
Answer: A. @EventPublisher
o A. @HandleEvent
o B. @EventListener
o C. @ListenToEvent
o D. @EventHandling
Answer: B. @EventListener
15. Which of the following annotations can be used to handle Spring application events
asynchronously?
o A. @Async
o C. @AsyncEventListener
o D. @AsyncHandler
o A. Using ApplicationContext.publishEvent()
o B. Using EventPublisher.publish()
o C. Using EventBus.publish()
o D. Using @EventPublisher.publish()
o A. Spring JMS
o B. Spring Integration
o C. Spring AMQP
o A. @JmsListener
o B. @QueueListener
o C. @MessageListener
o D. @Listener
Answer: A. @JmsListener
o A. @Service
o B. @MessageListener
o C. @JmsListener
o D. @Component
Answer: C. @JmsListener
20. Which annotation is used to configure the sending of messages to a JMS destination in Spring?
o A. @SendTo
o B. @MessageMapping
o C. @JmsTemplate
o D. @RabbitTemplate
Answer: A. @SendTo
21. Which of the following is a common Spring Boot starter used for building web applications?
o A. spring-boot-starter-web
o B. spring-boot-starter-data-jpa
o C. spring-boot-starter-security
o D. spring-boot-starter-mail
Answer: A. spring-boot-starter-web
22. Which Spring Boot starter is used for working with databases via JPA?
o A. spring-boot-starter-jdbc
o B. spring-boot-starter-data-jpa
o C. spring-boot-starter-data-mongodb
o D. spring-boot-starter-h2
Answer: B. spring-boot-starter-data-jpa
o A. spring-boot-starter-email
o B. spring-boot-starter-mail
o C. spring-boot-starter-smtp
o D. spring-boot-starter-gmail
Answer: B. spring-boot-starter-mail
24. Which Spring Boot starter is used to enable Spring Security in a project?
o A. spring-boot-starter-security
o B. spring-boot-starter-auth
o C. spring-boot-starter-login
o D. spring-boot-starter-authorization
Answer: A. spring-boot-starter-security
Spring MVC (Coding MCQs)
25. Which annotation is used to handle HTTP GET requests in Spring MVC?
o A. @RequestMapping
o B. @GetMapping
o C. @RequestParam
o D. @PostMapping
Answer: B. @GetMapping
26. Which of the following is used to bind a form submission to a model object in Spring MVC?
o A. @ModelAttribute
o B. @RequestBody
o C. @RequestParam
o D. @ModelForm
Answer: A. @ModelAttribute
27. Which annotation is used in Spring MVC to map a POST request to a method?
o A. @RequestMapping
o B. @PostMapping
o C. @RequestBody
o D. @RequestParam
Answer: B. @PostMapping
28. Which annotation in Spring MVC is used to handle HTTP requests based on method type and URI
pattern?
o A. @RequestMapping
o B. @RequestMethod
o C. @GetMapping
o D. @UrlMapping
Answer: A. @RequestMapping
SBQ questions
1. Dependency Injection (DI)
4. Explain the difference between Singleton and Prototype bean scopes in Spring.
o Answer:
▪ Singleton: A single instance of the bean is created and shared across the
entire Spring container.
o Answer: Spring Task Scheduler allows you to schedule tasks to run at specified
intervals or at specific times. It uses annotations like @Scheduled to configure tasks.
o Answer: You can use the @Scheduled annotation with a cron expression like this:
java
Copy code
// Task logic
o Answer:
12. How can you configure role-based access control in Spring Security?
o Answer: Role-based access control can be configured in Spring Security using the
@Secured or @PreAuthorize annotations, along with appropriate role checks. Roles
can be granted to users during authentication.
o Answer:
5. Spring Messaging
o Answer: Spring Messaging provides support for messaging protocols like JMS, AMQP,
and WebSocket, allowing Spring applications to send and receive messages.
o Answer: Message listeners in Spring JMS can be configured using the @JmsListener
annotation or by implementing the MessageListener interface and configuring it in
the listener container.
o Answer: JmsTemplate is a helper class in Spring that simplifies sending and receiving
JMS messages. It provides a higher-level abstraction over the JMS API.
o Answer: You can exclude a starter dependency by using the exclude attribute in the
@SpringBootApplication annotation or in the pom.xml file.
7. Spring MVC
27. What is the difference between @Controller and @RestController in Spring MVC?
o Answer:
▪ @Controller: Used to define a controller class that handles web requests and
returns view names (JSP, Thymeleaf, etc.).
28. How can you pass data from a controller to a view in Spring MVC?
o Answer: Data can be passed to a view in Spring MVC using Model or ModelAndView
objects, which are added in the controller method using the addAttribute method.
• Answer: The @Qualifier annotation is used to specify which bean to inject when there are
multiple candidates for autowiring, helping Spring to resolve ambiguity.
• Answer: A "bean" is an object that is managed by the Spring container. Beans are created,
configured, and wired by Spring IoC container.
32. What is the difference between @Autowired and @Inject annotations in Spring?
• Answer: Both annotations are used for dependency injection, but @Autowired is Spring-
specific, while @Inject is part of the Java standard (javax.inject) and has similar functionality.
33. How does Spring handle circular dependencies?
34. How do you configure a fixed delay schedule for a task in Spring?
• Answer: You can use the @Scheduled annotation with the fixedDelay attribute, which
specifies the delay between the completion of the last execution and the start of the next
execution.
java
Copy code
// Task logic
35. What is the difference between fixedRate and fixedDelay in Spring scheduling?
• Answer:
o fixedRate: Executes the task at a fixed rate, irrespective of when the last task
finished.
o fixedDelay: Executes the task after a specified delay from the end of the previous
task.
36. Can you schedule a task in Spring Boot based on cron expressions?
• Answer: Yes, Spring Boot allows scheduling tasks using cron expressions with the
@Scheduled(cron = "expression") annotation. Cron expressions allow fine-grained control
over task scheduling.
• Answer: TaskScheduler is an interface in Spring that provides methods for scheduling tasks
with flexible scheduling options. It is an abstraction over different scheduling frameworks like
ScheduledExecutorService.
38. What is the default time unit for fixedDelay and fixedRate in Spring Task Scheduling?
• Answer: The default time unit for both fixedDelay and fixedRate is milliseconds.
• Answer: Spring Security supports password hashing through the PasswordEncoder interface,
which provides implementations like BCryptPasswordEncoder, NoOpPasswordEncoder, etc.
40. What is the role of JWT (JSON Web Token) in Spring Security?
• Answer: JWT is used for stateless authentication, where a token is generated after a user logs
in and is included in subsequent requests to authenticate the user.
41. What is the difference between @Secured and @PreAuthorize in Spring Security?
• Answer:
43. How can you restrict access to a URL in Spring Security based on roles?
• Answer: @Async is used to run event listeners asynchronously, ensuring that the event
processing does not block the main thread.
46. How can you listen to an event in Spring without using @EventListener?
• Answer: You can implement the ApplicationListener interface and override the
onApplicationEvent method to listen to events.
47. What are some common use cases for Spring events?
• Answer: Common use cases include handling post-save actions (e.g., sending notifications
after data is saved), triggering background processes, and reacting to changes in the
application state.
• Answer: Custom events can be created by extending the ApplicationEvent class and then
publishing them using the ApplicationEventPublisher.
5. Spring Messaging
• Answer: @SendTo is used in Spring WebSocket to define the destination to which the
response should be sent after processing a message. It works in combination with
@MessageMapping.
• Answer: Spring JMS provides integration with ActiveMQ through the JmsTemplate and
@JmsListener annotation to send and receive messages in a Java Message Service (JMS)
environment.
• Answer: RabbitTemplate is a helper class in Spring AMQP for sending and receiving messages
to and from RabbitMQ queues.
7. Spring MVC
59. What is the role of @RequestMapping in Spring MVC?
60. What is the difference between @GetMapping and @PostMapping in Spring MVC?
• Answer:
• Answer: ModelAndView is used in Spring MVC to return both the model (data) and the view
(view name or template) from a controller method.
• Answer: Form handling in Spring MVC can be performed by using the @ModelAttribute
annotation to bind form data to an object and handling form submissions in controller
methods with @PostMapping.
64. What is the difference between constructor injection and setter injection in Spring?
• Answer:
o Setter Injection: Dependencies are provided through setter methods, which allows
optional dependencies and can be changed after object creation.
• Answer: Spring manages the lifecycle of beans by calling lifecycle methods like
@PostConstruct and @PreDestroy after initializing and before destroying the bean,
respectively.
• Answer: The @Primary annotation is used to indicate that a particular bean should be used
when multiple candidates are available for autowiring.
• Answer: The @Value annotation is used to inject values from property files, environment
variables, or expression language (SpEL) into Spring beans.
69. How can you run a task in Spring at fixed intervals using the @Scheduled annotation?
• Answer: You can specify intervals using the fixedRate or fixedDelay attributes of the
@Scheduled annotation, or use a cron expression for more advanced scheduling.
• Answer: A cron expression is a string that defines a schedule for running tasks. It consists of
six fields: second, minute, hour, day of the month, month, and day of the week. In Spring, it
is used with the @Scheduled(cron = "expression") annotation to schedule tasks.
71. How do you ensure that a task is executed periodically using Spring Task Scheduler?
• Answer: You can use the @Scheduled annotation with the fixedRate or cron attribute, or use
TaskScheduler to schedule tasks programmatically.
72. How would you schedule a task to run every day at midnight using Spring?
java
Copy code
// Task logic
• Answer: The @EnableScheduling annotation enables the Spring scheduler and allows you to
run tasks asynchronously with the help of the @Scheduled annotation.
76. How can you configure HTTP Basic authentication in Spring Security?
• Answer: You can configure HTTP Basic authentication by using http.httpBasic() in the Spring
Security configuration class.
77. What is the purpose of @PreAuthorize annotation in Spring Security?
78. What is the difference between Authentication and Authorization in Spring Security?
• Answer:
o Authentication is the process of verifying the identity of a user (e.g., username and
password).
• Answer: ApplicationEvent is the base class for all events in Spring. You can extend it to create
custom events that are published and listened to by Spring's event listeners.
java
Copy code
@Autowired
publisher.publishEvent(new CustomEvent(this));
• Answer: @EventListener is used to define methods that listen for specific events within the
Spring application context. The method will be invoked when the event is published.
83. How do you ensure that an event listener runs asynchronously in Spring?
• Answer: You can use the @Async annotation to make an event listener asynchronous,
allowing the event to be handled in a separate thread.
5. Spring Messaging
84. What is the role of the @MessageMapping annotation in Spring WebSocket?
85. What is the difference between @SendTo and @MessageMapping in Spring WebSocket?
• Answer:
86. What is Spring Integration, and how does it differ from Spring Messaging?
• Answer: Spring Integration is a framework for building enterprise integration patterns, while
Spring Messaging focuses on providing messaging support using protocols like WebSocket
and JMS. Spring Integration can use Spring Messaging as part of its implementation.
• Answer: @JmsListener is used to mark methods that will listen for JMS messages on a
specific destination. The method is invoked automatically when a message is received.
• Answer: RabbitTemplate is used to send and receive messages to and from RabbitMQ
queues. It is the primary interface for interacting with RabbitMQ in Spring AMQP.
• Answer: spring-boot-starter-parent is a special starter in Spring Boot that acts as a parent for
all Spring Boot projects. It provides default configurations, dependency management, and
plugin management.
93. How does Spring Boot’s spring-boot-starter-data-rest help in building REST APIs?
• Answer: You can return a JSON response by using the @RestController annotation or by
using @ResponseBody on a controller method to indicate that the response body should be
serialized as JSON.
• Answer: @RequestBody is used to bind the incoming HTTP request body to a method
parameter, typically used for reading JSON or XML data in RESTful web services.
• Answer: You can use @Valid or @Validated annotations to validate incoming requests, and
BindingResult can be used to capture validation errors for handling them.
• Answer: @ResponseStatus is used to specify the HTTP status code that should be returned
for a specific method or exception handler in Spring MVC.
• Answer: Dependency Injection provides loose coupling between classes, improves code
maintainability, testability, and flexibility by allowing easy swapping of components.
• Answer: The @Autowired annotation is used to automatically wire a bean by type. Spring will
automatically inject the required dependencies into the fields, constructors, or methods.
101. How does Spring handle multiple beans of the same type for autowiring?
• Answer: If multiple beans of the same type are found, Spring will throw an exception unless
one of the beans is marked with @Primary or @Qualifier is used to specify which bean
should be injected.
102. Can you use @Autowired to inject primitive types or simple values?
• Answer: Yes, @Autowired can inject primitive types, but it requires that the bean be a
suitable type or the value be configured properly (via @Value for simple values).
• Answer: The ApplicationContext is responsible for managing the lifecycle of beans, resolving
dependencies, and providing the beans to the application when needed.
• Answer: You can use @Scheduled(fixedDelay = 5000) to execute a task with a fixed delay of
5000 milliseconds (5 seconds) after the previous execution finishes.
106. How can you schedule a task to run at a fixed rate using Spring?
• Answer: You can use the @Scheduled(fixedRate = 10000) annotation to run a task at a fixed
rate of 10 seconds, regardless of the task's execution time.
• Answer: The cron expression 0 0 12 * * ? schedules a task to run at 12:00 PM (noon) every
day.
• Answer: You can disable a scheduled task by commenting out or removing the @Scheduled
annotation from the method or by using conditional checks within the method.
• Answer: Stateless authentication does not store any session or state between requests (e.g.,
JWT), while stateful authentication requires storing session information on the server side
(e.g., HTTP sessions).
113. How would you secure a REST API with JWT in Spring Security?
• Answer: You can secure a REST API with JWT by creating a custom filter that intercepts
incoming requests, validates the JWT token, and sets the authentication context.
java
Copy code
@Autowired
publisher.publishEvent(new CustomEvent(this));
• Answer: You can listen to events asynchronously by annotating the listener method with
@Async or by configuring an AsyncTaskExecutor.
• Answer: You can filter events by using the ApplicationListener interface with custom logic or
by specifying @EventListener with a condition.
118. Can Spring events be used for cross-cutting concerns like logging?
• Answer: Yes, Spring events can be used to handle cross-cutting concerns such as logging or
auditing by publishing and listening for specific events across the application.
5. Spring Messaging
119. What is the purpose of Spring AMQP (Advanced Message Queuing Protocol)?
• Answer: Spring AMQP provides support for sending and receiving messages using AMQP-
compliant brokers like RabbitMQ. It allows for message-driven application architecture.
120. How would you configure a Spring application to use JMS (Java Message Service)?
• Answer: @JmsListener is used to annotate methods that will listen for messages on a JMS
destination, such as a queue or topic.
122. How can you use Spring WebSocket for messaging in a Spring application?
• Answer: Spring WebSocket allows for bidirectional communication between the client and
server over a single, long-lived connection, enabling real-time messaging in web applications.
7. Spring MVC
• Answer: @PathVariable is used to extract values from URI path segments and bind them to
method parameters in Spring MVC controller methods.
131. How would you configure Spring MVC to return a view instead of JSON?
• Answer: You can return a view (e.g., JSP or Thymeleaf template) by using the @Controller
annotation and returning the view name from a controller method.
• Answer: @ResponseBody is used to indicate that the return value of a method should be
written directly to the HTTP response body, typically as JSON or XML.
133. What is the purpose of @ExceptionHandler in Spring MVC?