If a class is annotated with @Component, what should be done to have Spring automatically detect the annotated class and load it as a bean? (Choose the best answer.)
- A . Ensure a valid bean name in the @Component annotation is specified.
- B . Ensure a valid @ComponentScan annotation in the Java configuration is specified.
- C . Ensure a valid @Scope for the class is specified.
- D . Ensure a valid @Bean for the class is specified.
B
Explanation:
The @Component annotation indicates that a class is a candidate for auto-detection by Spring and can be registered as a bean in the application context. However, to enable this feature, the Java configuration class must also have the @ComponentScan annotation, which tells Spring where to look for annotated components.
Reference: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-stereotype-annotations
Which two options will inject the value of the daily.limit system property? (Choose two.)
- A . @Value(“#{daily.limit}”)
- B . @Value(“$(systemProperties.daily.limit)”)
- C . @Value(“$(daily.limit)”)
- D . @Value(“#{systemProperties[‘daily.limit’]}”)
- E . @Value(“#{systemProperties.daily.limit}”)
CD
Explanation:
The @Value annotation can be used to inject values from external sources into fields, constructor parameters, or method parameters. To inject a system property, the annotation can use either the ${…} placeholder syntax or the #{…} SpEL expression syntax. The former is simpler and more concise, while the latter is more powerful and flexible. Both syntaxes can access the systemProperties map, which contains all the system properties as key-value pairs.
Reference:
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-value-annotations :
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions :
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#expressions-beandef-xml-based
Which two options are REST principles? (Choose two.)
- A . RESTful applications use a stateless architecture.
- B . RESTful application use HTTP headers and status codes as a contract with the clients.
- C . RESTful applications cannot use caching.
- D . RESTful application servers keep track of the client state.
- E . RESTful applications favor tight coupling between the clients and the servers.
AB
Explanation:
REST stands for Representational State Transfer, which is an architectural style for designing web services that adhere to certain principles. One of these principles is statelessness, which means that each request from a client to a server must contain all the information necessary to understand the request, and that no session state is maintained on the server side. Another principle is uniform interface, which means that clients and servers communicate using a standardized protocol, such as HTTP, and use its features, such as headers and status codes, to exchange information about the resources and their representations.
Reference:
https://www.ibm.com/cloud/learn/rest :
https://restfulapi.net/statelessness/:
https://restfulapi.net/uniform-interface/
Which option is true about use of mocks in a Spring Boot web slice test? (Choose the best answer.)
- A . Mocking a Spring Bean requires annotating it with @MockBean annotation.
- B . If a Spring Bean already exists in the web slice test spring context, it cannot be mocked.
- C . Mocks cannot be used in a Spring Boot web slice test.
- D . Mocking a Spring Bean requires annotating it with @Mock annotation.
A
Explanation:
A web slice test is a type of test in Spring Boot that focuses on testing only the web layer of an application, without starting a full server or requiring a real database. To isolate the web layer from other dependencies, such as services or repositories, mocks can be used to simulate their behavior and return predefined responses. To create and inject a mock for an existing bean in the application context, the @MockBean annotation can be used on a field or a parameter in the test class. This annotation will replace any existing bean of the same type with a mock created by Mockito.
Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.testing-autoconfigured-web-test: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/mock/mockito/MockBean.html:
https://site.mockito.org/
Reference: https://tanzu.vmware.com/developer/guides/spring-boot-testing/
Which two statements are true regarding Spring Security? (Choose two.)
- A . Access control can be configured at the method level.
- B . A special Java Authentication and Authorization Service (JAAS) policy file needs to be configured.
- C . Authentication data can be accessed using a variety of different mechanisms, including databases and LDAP.
- D . In the authorization configuration, the usage of permitAll () allows bypassing Spring security completely.
- E . It provides a strict implementation of the Java EE Security specification.
AC
Explanation:
Spring Security is a framework that provides comprehensive security services for Java applications, such as authentication, authorization, encryption, session management, and more. One of its features is method security, which allows applying access control rules at the method level using annotations or XML configuration. Another feature is authentication, which is the process of verifying the identity of a user or a system. Spring Security supports various authentication mechanisms, such as username and password, tokens, certificates, etc., and can access authentication data from different sources, such as databases, LDAP directories, in-memory stores, etc.
Reference:
https://docs.spring.io/spring-security/site/docs/current/reference/html5/:
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#jc-method:
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#servlet-authentication
Reference: https://www.baeldung.com/security-none-filters-none-access-permitAll
Which two statements are true regarding a Spring Boot-based Spring MVC application? (Choose two.)
- A . The default embedded servlet container can be replaced with Undertow.
- B . Jetty is the default servlet container.
- C . Spring Boot starts up an embedded servlet container by default.
- D . The default port of the embedded servlet container is 8088.
- E . Spring MVC starts up an in-memory database by default.
AC
Explanation:
Spring Boot provides a convenient way to create Spring MVC applications with minimal configuration. By default, it uses Tomcat as the embedded servlet container, but it also supports other containers such as Jetty and Undertow. To use a different container, we just need to exclude the spring-boot-starter-tomcat dependency and include the corresponding starter for the desired container. For example, to use Undertow, we can add the following dependencies in our pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency>
Reference: https://www.javatpoint.com/spring-vs-spring-boot-vs-spring-mvc
Which two statements are true regarding Spring and Spring Boot Testing? (Choose two.)
- A . EasyMock is supported out of the box.
- B . @SpringBootTest or @SpringJUnitConfig can be used for creating an ApplicationContext.
- C . Mockito spy is not supported in Spring Boot testing by default.
- D . The spring-test dependency provides annotations such as @Mock and @MockBean.
- E . Integration and slice testing are both supported.
BE
Explanation:
Spring and Spring Boot provide various annotations and utilities to support testing of different layers of the application. To create an ApplicationContext for integration tests, we can use either @SpringBootTest or @SpringJUnitConfig annotations. The former is a specialized annotation that also provides additional features such as auto-configuration, web environment emulation, and test properties management. The latter is a general-purpose annotation that combines @ContextConfiguration and @ExtendWith(SpringExtension.class) annotations.
To perform slice testing, which focuses on testing a specific layer or feature of the application in isolation, we can use annotations such as @WebMvcTest, @DataJpaTest, @RestClientTest, etc. These annotations will only load the relevant beans for the tested slice and mock or stub the other dependencies.
Reference: https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/boot-features-testing.html
Refer to the exhibit.
Assume that the application is using Spring transaction management which uses Spring AOP internally.
Choose the statement that describes what is happening when the update1 method is called? (Choose the best answer.)
- A . There are 2 transactions because REQUIRES_NEW always runs in a new transaction.
- B . An exception is thrown as another transaction cannot be started within an existing transaction.
- C . There is only one transaction because REQUIRES_NEW will use an active transaction if one already exists.
- D . There is only one transaction initiated by update1() because the call to update2() does not go through the proxy.
D
Explanation:
When using Spring transaction management with annotation-driven mode, the @Transactional annotation will be processed by a Transaction Interceptor that implements the AOP advice interface. This interceptor will be applied to the target bean through a proxy that implements the same interface as the target bean. Therefore, when a method of the target bean is called from outside, it will actually invoke the proxy method, which will delegate to the interceptor and then to the actual target method.
However, when a method of the target bean is called from within the same bean, it will not go through the proxy and thus bypass the interceptor logic. In this case, when update1() calls update2(), it will not start a new transaction as specified by REQUIRES_NEW propagation level, but rather join the existing transaction initiated by update1() itself.
Which two statements are true concerning constructor injection? (Choose two.)
- A . If there is only one constructor the @Autowired annotation is not required.
- B . Constructor injection only allows one value to be injected.
- C . Constructor injection is preferred over field injection to support unit testing.
- D . Construction injection can be used with multiple constructors without @Autowired annotation.
- E . Field injection is preferred over constructor injection from a unit testing standpoint.
AC
Explanation:
Constructor injection is one of the ways to inject dependencies into a bean using its constructor parameters. Since Spring 4.3, if a bean has only one constructor, the @Autowired annotation can be omitted and Spring will use that constructor by default.
Constructor injection is generally recommended over field injection because it makes the dependencies of a bean explicit and immutable. It also facilitates unit testing because it allows us to easily provide mock dependencies through constructor arguments.
Given an ApplicationContext containing three bean definitions of type Foo with bean ids foo1, foo2, and foo3, which three @Autowired scenarios are valid and will allow the ApplicationContext to initialize successfully? (Choose three.)
- A . @Autowired public void setFoo (Foo foo) {…}
- B . @Autowired @Qualifier (“foo3”) Foo foo;
- C . @Autowired public void setFoo (@Qualifier (“foo1”) Foo foo) {…}
- D . @Autowired private Foo foo;
- E . @Autowired private Foo foo2;
- F . @Autowired public void setFoo(Foo foo2) {…}
BCF
Explanation:
The @Autowired annotation can be used to inject a dependency into a field, a constructor, or a setter method. However, if there are multiple beans of the same type in the application context, Spring will not be able to determine which one to inject by default. To resolve this ambiguity, we can use the @Qualifier annotation to specify the bean id of the desired dependency. Alternatively, we can use the bean id as the name of the field or the parameter of the setter method, and Spring will match it with the corresponding bean.
Which dependency enables an automatic restart of the application as code is changed during development of a Spring boot configuration on a web application? (Choose the best answer.)
- A . spring-boot-devtools
- B . spring-boot-initializr
- C . spring-boot-starter-devtools
- D . spring-boot-restart
C
Explanation:
Spring Boot provides a set of tools for improving the development experience, such as automatic restart, live reload, remote debugging, etc. These tools are included in the spring-boot-starter-devtools dependency, which can be added to the project’s pom.xml or build.gradle file. The automatic restart feature will monitor the classpath for changes and trigger a restart of the
application when necessary.
Spring puts each bean instance in a scope.
What is the default scope? (Choose the best answer.)
- A . prototype
- B . singleton
- C . request
- D . session
B
Explanation:
Spring supports different scopes for bean instances, such as singleton, prototype, request, session, etc. The scope determines how many instances of a bean are created and how they are shared among other components. The default scope is singleton, which means that only one instance of a bean is created per application context and it is shared by all components that depend on it.
Reference: https://stackoverflow.com/questions/17599216/spring-bean-scopes
Refer to the exhibit.
Which option is a valid way to retrieve the account id? (Choose the best answer.)
- A . Add @PathVariable(“id”) String accountId argument to the update() handler method.
- B . Add @PathVariable long accountId argument to the update() handler method.
- C . Add @RequestParam long accountId argument to the update() handler method.
- D . Add @RequestParam(“id”) String accountId argument to the update() handler method.
Which strategy is correct for configuring Spring Security to intercept particular URLs? (Choose the best answer.)
- A . The URLs can be specified via configuration (using authorizeRequests () and request matchers), with the most specific rule first and the least specific last.
- B . Spring Security can obtain URLs from Spring MVC controllers, the Spring Security configuration just needs a reference to the controller to be protected.
- C . The URLs are specified in a special properties file, used by Spring Security.
- D . The URLs can be specified via configuration (using authorizeRequests () and request matchers), with the least specific rule first and the most specific last.
A
Explanation:
Spring Security provides a fluent API for configuring web security based on URL patterns and request matchers. The authorizeRequests() method returns an expression that allows specifying access rules for different URLs using methods such as antMatchers(), regexMatchers(), mvcMatchers(), etc. The order of these rules matters, as they are evaluated from top to bottom. Therefore, it is recommended to put the most specific rules first and the least specific ones last.
Reference: https://www.baeldung.com/security-none-filters-none-access-permitAll
In which three ways are Security filters used in Spring Security? (Choose three.)
- A . To provide risk governance.
- B . To drive authentication.
- C . To manage application users.
- D . To provide a logout capability.
- E . To enforce authorization (access control).
- F . To encrypt data.
BDE
Explanation:
Spring Security uses a filter-based architecture to provide security services for web applications. A filter is an object that intercepts HTTP requests and responses and performs some logic before or after the request is processed by the servlet.
Spring Security provides a number of filters for different purposes, such as:
Authentication: Filters that handle the authentication process, such as UsernamePasswordAuthenticationFilter, BasicAuthenticationFilter, RememberMeAuthenticationFilter, etc.
User management: Filters that manage the user details and roles, such as SecurityContextPersistenceFilter, AnonymousAuthenticationFilter, ConcurrentSessionFilter, etc. Logout: Filters that handle the logout process, such as LogoutFilter and SecurityContextLogoutHandler.
Authorization: Filters that enforce access control rules based on the user’s authentication and roles, such as FilterSecurityInterceptor, ExceptionTranslationFilter, etc.
Reference: https://www.javadevjournal.com/spring-security/spring-security-filters/
Refer to the exhibit.
The above code shows a conditional @Bean method for the creation of a JdbcTemplate bean.
Which two statements correctly describe the code behavior? (Choose two.)
- A . @ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnBean (DataSource.class) for greater flexibility.
- B . @ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnMissingBean (DataSource.class) for greater flexibility.
- C . The @Bean annotation should be removed.
- D . A JdbcTemplate bean will be created when the DataSource class is in the classpath but there is no DataSource bean.
- E . A JdbcTemplate bean will be created when a bean named dataSource has already been created.
AE
Explanation:
The @Bean annotation is used to declare a method that returns an object that should be registered as a bean in the application context. The @ConditionalOnBean annotation is used to specify a condition for the bean creation based on the presence or absence of other beans in the application context. The name attribute of this annotation can be used to specify the bean name or names that must be present or absent for the condition to match. However, this approach is less flexible than using the value or type attribute, which can specify the bean class or classes that must be present or absent for the condition to match. Therefore, it is recommended to use @ConditionalOnBean(DataSource.class) instead of @ConditionalOnBean(name= “dataSource”) for greater flexibility.
The JdbcTemplate class is a Spring class that simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. To create a JdbcTemplate object, we need to pass a DataSource object as a constructor argument. The DataSource interface is a Java interface that represents a factory of connection objects. In this code, the jdbcTemplate() method takes a DataSource object as a parameter and returns a new JdbcTemplate object. This method is annotated with @Bean and @ConditionalOnBean(name= “dataSource”), which means that it will only create a JdbcTemplate bean when there is already a bean named dataSource in the application context.
What is a Spring Boot starter dependency? (Choose the best answer.)
- A . A setting for specifying which code you want Spring Boot to generate for you.
- B . A specific POM which you must build to control Spring Boot’s opinionated runtime.
- C . A pre-existing model project you can download and use as the basis of your project.
- D . An easy way to include multiple, coordinated dependencies related to a specific technology, like web or JDBC.
D
Explanation:
A Spring Boot starter dependency is a special type of dependency that provides a convenient way to add multiple, coordinated dependencies related to a specific technology or feature, such as web, JDBC, security, etc. A starter dependency usually has a name that starts with spring-boot-starter-followed by the name of the technology or feature. For example, spring-boot-starter-web is a starter dependency that includes all the dependencies needed for creating web applications with Spring MVC and RESTful services.
Reference: https://developer.ibm.com/tutorials/j-spring-boot-basics-perry/
Which two are required to use transactions in Spring? (Choose two.)
- A . Add @EnableTransactionManagement to a Java configuration class.
- B . Annotate a class, an interface, or individual methods requiring a transaction with the @Transactional annotation.
- C . A class must be annotated with @Service and @Transaction.
- D . A class requiring a transaction must implement the TransactionInterceptor interface.
- E . Write a Spring AOP advice to implement transactional behavior.
AB
Explanation:
Transactions are units of work that ensure data consistency and integrity by enforcing atomicity, consistency, isolation, and durability (ACID) properties. Spring provides an abstraction layer for transaction management that supports various transaction APIs such as JDBC, JPA, Hibernate, etc.
To use transactions in Spring, we need to do two things:
Enable transaction management by adding @EnableTransactionManagement annotation to a Java configuration class or tx:annotation-driven/ element to an XML configuration file.
Declare transactional boundaries by annotating a class, an interface, or individual methods with the @Transactional annotation. This annotation indicates that the execution of the annotated element should be wrapped in a transaction.
Reference: 5
Reference: https://www.baeldung.com/transaction-configuration-with-jpa-and-spring
Which two statements are true regarding the RestTemplate class? (Choose two.)
- A . It supports asynchronous non-blocking model.
- B . It automatically supports sending and receiving Java objects.
- C . It provides convenience methods for writing REST clients.
- D . It provides convenience methods for writing REST services.
- E . Sending an HTTP request with a custom header is not possible when using RestTemplate.
BC
Explanation:
The RestTemplate class is a Spring class that provides an easy way to communicate with RESTful web services from within an application. It offers several convenience methods for performing HTTP requests and handling HTTP responses, such as getForObject(), postForEntity(), exchange(), etc. It also supports automatic conversion of Java objects to and from JSON or XML using HttpMessageConverter instances.
Reference: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/ RestTemplate.html
Which statement is true? (Choose the best answer.)
- A . @ActiveProfiles is a class-level annotation that is used to instruct the Spring TestContext Framework to record all application events that are published in the ApplicationContext during the execution of a single test.
- B . @ActiveProfiles is a class-level annotation that you can use to configure how the Spring TestContext Framework is bootstrapped.
- C . @ActiveProfiles is a class-level annotation that you can use to configure the locations of properties files and inlined properties to be added to the set of PropertySources in the Environment for an ApplicationContext loaded for an integration test.
- D . @ActiveProfiles is a class-level annotation that is used to declare which bean definition profiles should be active when loaded an ApplicationContext for an integration test.
D
Explanation:
A bean definition profile is a named logical grouping of bean definitions that can be activated or deactivated in different environments. For example, we can define different profiles for development, testing, and production environments. Spring provides the @Profile annotation to mark a bean definition or a configuration class as belonging to a specific profile. To activate a profile, we can use the spring.profiles.active property or the ConfigurableEnvironment.setActiveProfiles() method.
The @ActiveProfiles annotation is a class-level annotation that is used in conjunction with the Spring TestContext Framework to declare which profiles should be active when loading an ApplicationContext for an integration test. This annotation can be applied to any class annotated with @ContextConfiguration or a meta-annotation that is composed of @ContextConfiguration.
Reference: https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/integration-testing.html
Which two statements are true about REST? (Choose two.)
- A . REST is a Protocol.
- B . REST is Stateful.
- C . REST is Reliable.
- D . REST is Interoperable.
- E . REST is Relative.
AD
Explanation:
Reference: https://www.tutorialspoint.com/restful/restful_introduction.htm
Spring Boot will find and load property files in which of the following? (Choose the best answer.)
- A . A *.properties file matching the name of the class annotated with @SpringBootApplication.
- B . config.properties or config.yml, usually located in the classpath root.
- C . application.properties or application.yml, usually located in the classpath root.
- D . env.properties or env.yml, usually located in the classpath root.
C
Explanation:
Reference: https://stackabuse.com/how-to-access-property-file-values-in-spring-boot/
Which three dependencies are provided by the spring-boot-starter-test? (Choose three.)
- A . Cucumber
- B . Hamcrest
- C . spring-test
- D . Junit
- E . EasyMock
- F . PowerMock
BDE
Explanation:
Reference: https://www.baeldung.com/spring-boot-testing
Which two statements are correct regarding Spring Boot auto-configuration customization? (Choose two.)
- A . Use the @AutoConfigureAfter or @AutoConfigureBefore annotations to apply configuration in a specific order.
- B . Disable specific auto-configuration classes by using the exclude attribute on the @EnableAutoConfiguation annotation.
- C . Provide customized auto-configuration by subclassing the provided Spring Boot auto-configuration classes.
- D . Enable component scanning within auto-configuration classes to find necessary components.
- E . Control the order of auto-configuration classes applied with @AutoConfigureOrder.
AB
Explanation:
Reference: https://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/html/using-boot-auto-configuration.html
Which two statements about the @Autowired annotation are true? (Choose two.)
- A . @Autowired fields are injected after any config methods are invoked.
- B . Multiple arguments can be injected into a single method using @Autowired.
- C . By default, if a dependency cannot be satisfied with @Autowired, Spring throws a RuntimeException.
- D . If @Autowired is used on a class, field injection is automatically performed for all dependencies.
- E . @Autowired can be used to inject references into BeanPostProcessor and BeanFactoryPostProcessor.
BC
Explanation:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html
B. Multiple arguments can be injected into a single method using @Autowired.
This is true because the @Autowired annotation can be applied to methods with arbitrary names and multiple arguments, as shown in the example in Using @Autowired.
C. By default, if a dependency cannot be satisfied with @Autowired, Spring throws a RuntimeException.
This is true because the @Autowired annotation has a required attribute that is true by default, meaning that the dependency is mandatory. If Spring cannot find a matching bean to inject, it will throw a BeanCreationException, which is a subclass of RuntimeException. To avoid this exception, we can set the required attribute to false, which will allow Spring to skip the injection if no matching bean is found
Which two statements are correct regarding the @EnableAutoConfiguration annotation? (Choose two.)
- A . It is a meta-annotation on the @SpringBootApplication composed annotation.
- B . It enables auto-configuration of the ApplicationContext by attempting to guess necessary beans.
- C . It is meta-annotation on the @SpringBootConfiguration composed annotation.
- D . It has the same effect regardless of the package of the class that is annotated with it.
- E . It ensures auto-configuration is applied before user-defined beans have been registered.
AB
Explanation:
Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/EnableAutoConfiguration.html
Which two statements are true concerning the BeanPostProcessor Extension point? (Choose two.)
- A . BeanPostProcessors are called before the dependencies have been injected.
- B . Custom BeanPostProcessors can be implemented for Spring applications.
- C . BeanPostProcessors are called before the BeanFactoryPostProcessors.
- D . BeanPostProcessors are called during the initialization phase of a bean life cycle.
- E . BeanPostProcessors cannot be ordered in a Spring Boot application.
BD
Explanation:
B. Custom BeanPostProcessors can be implemented for Spring applications.
This is true because the BeanPostProcessor interface defines callback methods that you can implement to provide your own (or override the container’s default) instantiation logic, dependency resolution logic, and so forth1. You can configure multiple BeanPostProcessor instances, and you can control the order in which these BeanPostProcessor instances run by setting the order property1. For example, in this tutorial, a custom BeanPostProcessor is implemented to integrate Guava’s EventBus with Spring beans.
D. BeanPostProcessors are called during the initialization phase of a bean life cycle.
This is true because the BeanPostProcessor interface consists of exactly two callback methods: postProcessBeforeInitialization and postProcessAfterInitialization. When such a class is registered as a post-processor with the container, for each bean instance that is created by the container, the post-processor gets a callback from the container both before container initialization methods (such as InitializingBean.afterPropertiesSet() or any declared init method) are called, and after any bean initialization callbacks1.
Reference: https://docs.spring.io/spring-framework/docs/3.0.0.M3/reference/html/ch04s07.html
Which two statements are true about @Controller annotated classes? (Choose two.)
- A . The @Controller annotated classes can only render views.
- B . The classes are eligible for handling requests in Spring MVC.
- C . The classes must be annotated together with @EnableMvcMappings to be discovered via component scanning.
- D . @Controller is interchangeable with @RestController with no extra code changes for the methods inside the class.
- E . The @Controller annotation is a stereotype annotation like @Component.
BE
Explanation:
B. The classes are eligible for handling requests in Spring MVC.
This is true because the @Controller annotation marks a class as a web request handler, and it is typically used with the @RequestMapping annotation to map specific URLs to methods1. The @Controller annotation also allows the class to be recognized as a Spring-managed component through the classpath scanning2.
E. The @Controller annotation is a stereotype annotation like @Component.
This is true because the @Controller annotation is a specialization of the generic stereotype @Component annotation, which allows a class to be recognized as a Spring-managed component3. The @Controller annotation extends the use-case of @Component and marks the annotated class as a business or presentation layer4.
Reference:
https://www.baeldung.com/spring-mvc-handler-adapters https://www.dineshonjava.com/stereotype-annotations-in-spring/
Which three types can be used as @Controller method arguments? (Choose three.)
- A . Locale
- B . Principal
- C . Language
- D . Session
- E . Request
- F . HttpSession
ABF
Explanation:
Which three statements are advantages of using Spring’s Dependency Injection? (Choose three.)
- A . Dependency injection can make code easier to trace because it couples behavior with construction.
- B . Dependency injection reduces the start-up time of an application.
- C . Dependencies between application components can be managed external to the components.
- D . Configuration can be externalized and centralized in a small set of files.
- E . Dependency injection creates tight coupling between components.
- F . Dependency injection facilitates loose coupling between components.
CDF
Explanation:
C. Dependencies between application components can be managed external to the components. This is true because dependency injection allows the application components to declare their dependencies without creating or obtaining them directly. Instead, the dependencies are provided by an external entity, such as the Spring container, which can read the configuration from XML files, annotations, or Java code1.
D. Configuration can be externalized and centralized in a small set of files.
This is true because dependency injection enables the separation of concerns between the application logic and the configuration. The configuration can be stored in a small number of files that can be easily changed without affecting the source code2.
F. Dependency injection facilitates loose coupling between components.
This is true because dependency injection reduces the direct dependencies between components, making them more reusable and testable. It also allows for easier substitution of different implementations of the same interface3.