Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's New in CDI 2.0 (JSR 365)

What's New in CDI 2.0 (JSR 365)

Contexts and Dependency Injection has become an integral part of Java to leverage dependency injection and bean management aside of EJB. The current CDI 1.2 is widely used amongst Java Enterprise 7 applications. The Expert Group is working since Fall 2014 on the next version of the specification with the goal to present the final CDI 2.0 spec in Q2/2016, which will be part of Java Enterprise 8.

You will learn about some of the upcoming highlights such as asynchronous events or how to boot CDI with Java SE. These features are already part of the draft release. You will get an overview of the changes, the Java 8 support, and how to apply the new features in your application. This is the right session for you if you are already a CDI user or want to become one and those that are interested in the progress of JSR 365 to build first-citizen CDI applications.

Mark Paluch

March 08, 2016
Tweet

More Decks by Mark Paluch

Other Decks in Programming

Transcript

  1. CDI Timeline Dec 2009 CDI 1.0 (Java EE 6) Jun

    2013 CDI 1.1 (Java EE 7) Apr 2014 CDI 1.2 (M R) Sep 2014 CDI 2.0 (Kickoff) June 2016 CDI 2.0 (Release)
  2. CDI 2.0 Parts • CDI core • Java SE •

    Java EE Integration • Support implementations for two TCK modes
  3. Asynchronous Events • Notify event observers asynchronously • One or

    more different threads • Decoupled from synchronous events
  4. Asynchronous Events • Exceptions and Synchronization with CompletionStage • Active

    scopes: Request, Application • Custom scopes depend on the implementation
  5. Ordered Events • Add @Priority to event observers • Aids

    observer ordering • Total global order determined when the event is fired
  6. public void earlier(@Observes @Priority(2499) MyEvent event) {
 // yay! I'm

    first
 System.out.println("Notified before all other observers");
 }
 public void observer(@Observes MyEvent event) {
 System.out.println("Default priority");
 } public void later(@Observes @Priority(2501) MyEvent event) {
 System.out.println("Notified after all other observers");
 }
  7. Meta-Data Builder API • Standardized API • AnnotatedTypes, Beans, BeanAttributes,

    InjectionPoints, and ObserverMethods • Builder and Configurator-style
  8. public class MyExtension {
 public void afterBeanDiscovery( @Observes AfterBeanDiscovery event)

    {
 BeanBuilder<MyBean> builder = Builders.bean(MyBean.class); builder.configure().addQualifier(new TransactionalLiteral());
 Bean<MyClass> bean = builder.build();
 
 event.addBean(bean);
 } } Meta-Data Builder API
  9. Bootstrap API public static void main(String[] args) {
 
 try(CDI<Object>

    cdi = CDI.current()) {
 cdi.select(MyApp.class).get().runMyApplication();
 }
 }
 
 public class MyApp{
 
 public void runMyApplication(){
 // ...
 }
 }
  10. What else is in work? • Java 8: Repeating annotations

    • Proxying of classes with final methods • AOP on produced and custom beans
  11. Get in touch Web: http://www.cdi-spec.org/ Mailing list: [email protected] IRC: irc://freenode.net/#cdi-dev

    Twitter: @cdispec Github: https://github.com/cdi-spec CDI 2.0 JCP page: http://jcp.org/en/jsr/summary?id=365
  12. Q&A