Skip to Content

VMware 2V0-72.22: What are the Characteristics of Bean Declared in Java @Configuration Class?

Learn about the default scope, initialization, and naming conventions for beans declared in a Java @Configuration class. Discover how to make the configuration profile-specific using @Profile annotation. Perfect for preparing for the VMware 2V0-72.22 certification exam.

Table of Contents

Question

AppConfig is a Java configuration class. Which two statements are true? (Choose two.)

@Configuration
punlic class AppConfig {
@Ben
public ClientService clientService() {
ClientServiceImpl clientService = new ClientServieImpl();
clientService.addClientDao(new ClientDao());
return clientService;
}
}

A. The clientService bean declared will have prototype scope by default.
B. The name of the clientService() method is invalid and will throw an error.
C. The clientService bean will be lazy initialized the first time accessed.
D. The bean is of type clientService and by default will be a Singleton.
E. The Java configuration can be profile specific by adding a @Profile annotation.

Answer

D. The bean is of type clientService and by default will be a Singleton.
E. The Java configuration can be profile specific by adding a @Profile annotation.

Explanation

In a Java configuration class annotated with @Configuration, any method annotated with @Bean is used to declare a bean. By default, the bean will be a singleton, meaning only one instance of the bean will be created and shared across the application context. The bean name will default to the method name, in this case “clientService”.

The @Profile annotation can be added to the configuration class to make it profile-specific. This allows activating different configurations based on the active profile(s), enabling environment-specific bean definitions.

Regarding the other options:
A is incorrect because the default scope is singleton, not prototype. Prototype scope beans are created each time they are requested.
B is incorrect because the method name is valid. The bean name defaults to the method name.
C is incorrect because by default, singleton beans are eagerly initialized when the application context is created, not lazily initialized on first access. Lazy initialization requires explicitly setting the bean to be lazy-initialized.

VMware 2V0-72.22 certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the VMware 2V0-72.22 exam and earn VMware 2V0-72.22 certification.