1. Use multiple @ Qualifiers at the same injection point to perform the following steps:
You can use multiple restricted injection solutions to divide your injection targets in one step.
We have fixed the limit to explain SuperFast and StandardFrameRelaySwitchingFlubber to demonstrate this method. In that case, we have the second transmitter StandardFrameRelaySwitchingFlubber and SuperFast. We need to note that the transmitter not only has StandardFrameRelaySwitchingFlubber, but also has SuperFast.
First, let's determine the limitation and resolution, as shown below:
Example 1. define a new SuperFast restricted note Solution
Package org. cdi. advocacy;
...
@ Qualifier @ Retention (RUNTIME) @ Target ({TYPE, METHOD, FIELD, PARAMETER })
Public @ interface SuperFast {
}
Example 2. Define another new StandardFrameRelaySwitchingFlubber restricted injection solution
Package org. cdi. advocacy;
...
@ Qualifier @ Retention (RUNTIME) @ Target ({TYPE, METHOD, FIELD, PARAMETER })
Public @ interface StandardFrameRelaySwitchingFlubber {
}
OK. The lower part of the code is used for the SuperFastAtmTransport with @ SuperFast and @ StandardFrameRelaySwitchingFlubber restrictions.
Example 3. SuperFastAtmTransport use two restricted injection Solutions
Package org. cdi. advocacy;
@ SuperFast @ StandardFrameRelaySwitchingFlubber
Public class SuperFastAtmTransport implements ATM transport {
Public void communicateWithBank (byte [] datapacket ){
System. out. println ("communicating with bank via the Super Fast transport ");
}
}
OK. We have added StandardFrameRelaySwitchingFlubber to StandardAtmTransport.
Example 4: StandardAtmTransport use a fixed-limit injection solution
Package org. cdi. advocacy;
@ StandardFrameRelaySwitchingFlubber @ Default
Public class StandardAtmTransport implements ATM transport {
Public void communicateWithBank (byte [] datapacket ){
System. out. println ("communicating with bank via Standard transport ");
}
}
Next, I hope my self-propelled cabinet worker will use the SuperFast transmission and carry the StandardFrameRelaySwitchingFlubber. I will use it when the injection points are the same, for example:
Example 5: Change AutomatedTellerMachineImpl to enable two restricted injection solutions.
Public class AutomatedTellerMachineImpl implements AutomatedTellerMachine {
@ Inject @ SuperFast @ StandardFrameRelaySwitchingFlubber
Private ATM transport;
...
Deposit called
Communicating with bank via the Super Fast transport
Exercise: Create a transmitter with @ SuperFast, @ StandardFrameRelaySwitchingFlubber and @ Alternative. Then use beans. xml to activate SuperFast, StandardFrameRelaySwitchingFlubber, and Alternative support. Your resolution is sent to me through the CDI Group mail list. The first post will be pasted on the CDI wall.
Exercise by the reader: Change the entry point limit to use StandardAtmTransport only. Your resolution is sent to me through the CDI Group mail list. The first post will be pasted on the CDI wall.