31. How are static resources served in a Spring Boot web application?
a) Through a dedicated controller
b) By placing them in the /static or /public directory
c) Using a specialized static server
d) By manual configuration in the application.properties file
Answer:
b) By placing them in the /static or /public directory
Explanation:
Static resources like CSS, JavaScript, and images in a Spring Boot web application can be served by placing them in the /static or /public directory of the application. Spring Boot automatically configures these as static resource locations.
32. What is the primary use of the @Query annotation in Spring Data JPA?
a) To create native SQL queries
b) To define a JPA query for a repository method
c) To configure database connections
d) To create HTML templates
Answer:
b) To define a JPA query for a repository method
Explanation:
The @Query annotation in Spring Data JPA is used to define a JPA query for a repository method. It allows custom query definitions directly on repository interface methods.
33. In Spring Boot, what is the purpose of the @EnableAutoConfiguration annotation?
a) To enable batch processing
b) To automatically configure Spring framework based on classpath settings
c) To configure application properties
d) To enable WebSocket functionality
Answer:
b) To automatically configure Spring framework based on classpath settings
Explanation:
The @EnableAutoConfiguration annotation in Spring Boot is used to enable auto-configuration of the Spring application context, attempting to guess and configure beans that are likely needed based on the classpath contents.
34. How can you secure a RESTful endpoint in Spring Boot?
a) Using the @Secure annotation
b) By defining security configurations in application.properties
c) Through Spring Security and its configuration
d) By using a separate security server
Answer:
c) Through Spring Security and its configuration
Explanation:
RESTful endpoints in Spring Boot can be secured using Spring Security, which provides comprehensive security services, including authentication and authorization.
35. What is the purpose of the @JsonBackReference and @JsonManagedReference annotations in Spring Boot?
a) To configure RESTful web services
b) To handle recursive relationships in JSON serialization and deserialization
c) To define the primary and foreign keys in a database
d) To configure application properties
Answer:
b) To handle recursive relationships in JSON serialization and deserialization
Explanation:
@JsonBackReference and @JsonManagedReference annotations are used in Spring Boot to handle recursive relationships during JSON serialization and deserialization, preventing issues like infinite recursion.
36. What is the role of the @CrossOrigin annotation in a Spring Boot application?
a) To enable batch processing
b) To configure application security
c) To define a scheduled task
d) To allow cross-origin requests in a web application
Answer:
d) To allow cross-origin requests in a web application
Explanation:
The @CrossOrigin annotation in Spring Boot enables cross-origin requests on specific handler classes or handler methods, allowing resources to be accessed from a domain other than the domain where the resource originated.
37. In Spring Boot, how can you externalize configuration?
a) By using environment variables
b) Through application.properties or application.yml files
c) By creating XML configuration files
d) Both a) and b)
Answer:
d) Both a) and b)
Explanation:
Configuration in Spring Boot can be externalized using environment variables and properties files (application.properties or application.yml), allowing for different configurations in different environments.
38. What is the purpose of the @PathVariable annotation in Spring Boot?
a) To bind a method parameter to a path variable in a URL
b) To define a request parameter
c) To configure request headers
d) To return a response body
Answer:
a) To bind a method parameter to a path variable in a URL
Explanation:
The @PathVariable annotation in Spring Boot is used in controller methods to bind a method parameter to a named variable in a URI template.
39. Which component is responsible for handling view resolution in a Spring Boot web application?
a) JdbcTemplate
b) ViewResolver
c) DataSource
d) WebMvcConfigurer
Answer:
b) ViewResolver
Explanation:
In a Spring Boot web application, the ViewResolver component resolves views by name and determines which view technology to use for rendering the UI.
40. How can you enable transaction management in a Spring Boot application?
a) By using the @Transactional annotation
b) Through XML configuration
c) By manually managing transactions in the service layer
d) By using a specialized transaction management server
Answer:
a) By using the @Transactional annotation
Explanation:
The @Transactional annotation enables transaction management in Spring Boot. It can be applied to classes or methods that require transactional behavior.
Complete Spring Boot MCQ Questions and Answers series:
Comments
Post a Comment
Leave Comment