O'Reilly logo

Java EE 7 Developer Handbook by Peter A. Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced CDI

In this section, we will advance the context and dependency injection to listening and acting on the lifecycle events, and choose between alternative implementations through configuration.

The lifecycle component example

In the section, CDI initialization and destruction, we discussed the lifecycle methods for the CDI managed beans. Let us look at a unit test example that demonstrates the concepts. We will build the other side of the CreditProcessor example, which is the premium rate version.

package je7hb.standalone; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @Premium public class PremiumCreditProcessor implements CreditProcessor { @Override public void check(String account) { if (!account.trim().startsWith("1234")) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required