Java ee6 standard CDI tutorial Part 5

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.