From the course: Java EE: Contexts and Dependency Injection

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

What are alternatives?

What are alternatives?

From the course: Java EE: Contexts and Dependency Injection

Start my 1-month free trial

What are alternatives?

- [Instructor] The alternative feature allows the developer to provide an alternative implementation of a bean and to use it for different purposes. Alternatives are commonly used for the following purposes: handling client-specific business logic, to specify beans that are valid for a particular deployment scenario, perhaps based on locale, and to create test versions of beans to be used for testing. Perhaps they're lightweight versions of the real thing. To make an alternative bean available for use, it must be annotated alternative and be defined in the beans.xml file with the alternative element. In this example, the customer web service test alternative bean implements the same interface as the real customer web service bean. And the injection point in the class uses the customer web service interface as the field type. To activate the alternative, and to use it instead of the real implementation, it must be defined in the beans.xml file, as shown above. Now when the application…

Contents