Contexts & Dependency Injection for Java

CDI 1.2 released

Posted by Antoine Sabot-Durand on Apr 14, 2014 | Comments

After one year of existence, the CDI 1.1 specification is updated by a maintenance release. This maintenance review known as CDI 1.2 was adopted by the JCP with 24 yes and one Expert Member forgetting to vote. The minor increment (from 1.1 to 1.2) instead of a 1.1-SP1 is due to the the fact that we changed the javadoc and the TCK but beyond that there are far less changes from 1.1 to 1.2 than from 1.0 to 1.1. That’s being said, CDI 1.2 brings a lot of clarifications and small behavior changes. Let’s check what’s on the menu.

Major changes

Some of these changes are only big clarifications but some other have an impact on the implementations (these last ones have an asterisk in their title below). In order to use them you’ll have to grab a CDI 1.2 implementation (more info at the end of this post).

Rethinking the default bean discovery mode *

The default bean discovery mode (annotated) that allows CDI to be activated by default in Java EE 7 without beans.xml, file was the root of a lot of issues with other frameworks implementing the AtInject specification (JSR-330) or with libraries thought to be used with such frameworks. To solve these issues we changed the set of Bean defining annotations (class annotations that make a class an implicit bean candidate) :

  • all pseudo scopes annotations except @Dependent were removed,

  • @Interceptor and @Decorator were added,

  • all stereotype annotations (annotations annotated with @Stereotype) were added.

Clarification of conversation resolution

Conversation resolution mechanism could bring conflicts with servlet spec as stated in CDI-411.

We clarified the fact that implementation should prevent these conflict during conversation resolution in conversation context lifecycle

Rework on event chapter

You think you know how event resolution works in CDI? If you gained this knowledge by a careful reading of chapter 10 of the specification, think again. This chapter had a lot of approximations and confusing mentions. It was reviewed and partly rewritten (and yes, @Any is totally useless for Event<> injection, event firing and observers resolution).

This chapter is worth the re-reading.

You can also check the diff, if you prefer.

BeanManager more permissive during initialization *

In CDI 1.1, some BeanManager methods couldn’t be called before the AfterDeploymentValidation was fired. A non portable behavior was tolerated to allow use of these in AfterBeanDiscovery observers. These brought confusing mention in specification and javadoc. We decided to standardized the non portable behavior (not a big deal since all implementations adopted it). So in CDI 1.2 the following BeanManager method can be called (with restrictions) in an AfterBeanDiscovery observer method:

  • getBeans(String),

  • getBeans(Type, Annotation…​),

  • getPassivationCapableBean(String)

  • resolve(Set),

  • resolveDecorators(Set, Annotation…​),

  • resolveInterceptors(InterceptionType, Annotation…​),

  • resolveObserverMethods(Object, Annotation…​),

  • validate(InjectionPoint).

more details on the diff

Clarification on container lifecycle event use

We clarified the fact these event should only be used during invocation of their observer methods. Check the diff of the whole 11.5 paragraph

Rework on the initialization phase parts

Description of initialization phase in chapter 11 & 12 was very messing. No chronological ordering of event fired by the container, missing events. For instance we forgot to speak with ProcessInjectionPoint and ProcessBeanAttributes and ProcessProducer was wrongly placed before ProcessBean in chapter 12. So if you’re planning to write portable extensions you should perhaps re-read chapter 12. Not yet a page turner but far more accurate than it use to be.

CDI API now officially supporting OSGi

We integrated all OSGi bundle information in CDI 1.2 api jar. So now it’ll be easier to use CDI in OSGi environment. Before that you had to grab a special OSGi release of CDI 1.1 to have the good bundle info in our META-INF/MANIFEST.MF.

More minor changes

You can check the change section of the spec to check the more minor changes we introduces in the spec. We also work on Javadoc to synchronize it with the specification by updating it or correcting the spec when api description were wrong.

Concrete stuff

You’ll find concrete raw and final data in the links below.

  • You’re interested by the release notes? it’s here.

  • You want to check the diff between CDI 1.1 spec and CDI 1.2 spec? You’ll find it there

  • You can’t wait to read this new spec, the Javadoc or use with the API or TCK? Go to our download page

  • You want to start coding in CDI 1.2? Good news reference implementation (Weld 2.2.0) is available and provide all that’s needed to be integrated to a Java EE 7 server. More information on Weld 2.2.0 announcement

CDI EG meeting 12/16/2013 notes on CDI 1.2

Posted by Antoine Sabot-Durand on Dec 16, 2013 | Comments

The following people assisted this meeting :

  • Mark Struberg (ms)

  • Joseph Bergmark(jb)

  • Jozef Hartinger (jh)

  • Martin Kouba (mk)

  • JJ Snyder (jj)

  • Phil Zampino (pz)

  • Antoine Sabot-Durand (asd)

Proposed Agenda

The following agenda was proposed

  1. Discussion on the last ticket pending : CDI-395 Public fields in extensions should not be allowed

  2. Last second ticket

  3. Next step for the MR.

Discussion on CDI-395

We were waiting on implementation feedback on this point. jh told us that there was too much risk to create retro-compatibility issues. So it was decided to remove CDI-395 from MR.

Last minute issues

Jira Description Decision Note

CDI-408

bean-discovery-mode="annotated" and Producers/Observers in @Dependent beans

in MR

CDI-410

@RequestScoped Javadoc outdated

in MR

CDI-388

Session bean specialization example is not valid

in MR

CDI-376

BeanManager#getProducerFactory return type differs between API and spec

in MR

CDI-411

CDI conversation activation conflicts with the Servlet spec

Pending

needs some test before decicing if we can include it in MR. Test leaded by jh

Next Step

The list is now closed (except for 411) It’s accessible here and in Jira. The Maintenance Release will be officially launch on the 6th january week. By then, work and discussion can start on the ticket chosen for this MR.

Conclusion of EG preparation on CDI 1.2

Posted by Antoine Sabot-Durand on Dec 16, 2013 | Comments

Updated on 01/07/2014

We finished to deal with the list of 28 Jira we planned to introduce or not in MR. So 24 of them will be in MR and 4 won’t. The list is also accessible on Jira.

Jira Description Decision Note

CDI-413

Update outdated license

in MR

CDI-408

bean-discovery-mode="annotated" and Producers/Observers in @Dependent beans

in MR

CDI-410

@RequestScoped Javadoc outdated

in MR

CDI-388

Session bean specialization example is not valid

in MR

CDI-376

BeanManager#getProducerFactory return type differs between API and spec

in MR

CDI-377

automatic JSR-330 annotation processing problematic

in MR

Mention needed and perhaps a new feature

CDI-380

Clarify SessionScoped

in MR

We should be less descriptive and like for CDI-381 add a general statement telling that other spec/extensions can change the behavior of built-in scope

CDI-372

clarify behavior of implicit bean archive

in MR

The notion of Bean Archive is introduce in Chapter 12, we should do an introduction before

CDI-320

Clarify whether ProcessAnnotatedType should be fired for annotations

in MR

According to pm it shouldn’t and we should clarify this

CDI-318

@WithAnnotations types can appear on any supertype

in MR

Mainly Javadoc correction on @WithAnnotation

CDI-280

behavior of CDI bean @Specializes session bean is undefined

in MR

could benefit some clarification

CDI-220

Clarify interceptors are not associated with the result of a producer method/field

in MR

CDI-405

Reword the description of @RequestScoped and @ApplicationScoped in section 2.4.1

in MR

CDI-401

Clarify the meaning of "bean class local view"

in MR

CDI-398

Clarify that an array with a variable component type or parameterized component type containing wildcards is not a valid bean type

in MR

CDI-392

Clarify when the operations of BeanManager can be called

in MR

CDI-386

Two examples in section 5.2.4 contradict the rules of the same section

in MR

CDI-382

Clarify interceptors are not associated with the result of a producer method/field

in MR

CDI-381

Additional implementations of Request Context

in MR

we should add general statement telling that extension can change the behavior of built-in scope

CDI-406

Make stereotypes bean defining annotations

in MR

CDI-404

adding bean-defining annotations for Interceptor while setting bean-discovery-mode="annotated"

in MR

CDI-389

Revert CDI-85

in MR

we revert to CDI 1.0 behavior but we will have to propose something better in CDI 2.0

CDI-397

Clarify Section 6.6.3 regarding singletons

in MR

we should go a little beyond and check all occurrences of "singleton" in the spec to clarify if it’s an singleton session bean or a singleton scope

CDI-411

CDI conversation activation conflicts with the Servlet spec

in MR

Solution exist at different level. We should at least put a mention in the spec and o something at impl level

CDI-379

Clarify life cycle of RequestScoped

out MR

each spec should detail how they stick to built-in scope

CDI-370

Expand @RequestScoped and @SessionScoped to account for WebSocket

out MR

It’s the responsibility of Websocket spec. We should ensure they take the point before closing the ticket

CDI-77

Clarify what happens when the user creates a unbound recursive injection with Dependent scoped beans

out MR

Container doesn’t have to support this : the ticket should be closed

CDI-395

Public fields in extensions should not be allowed

out MR

it can bring backwards compatibility problem to correct this issue. We should see if impls allows it today. If it’s not the case it could be safely added to the MR