Friday, April 15, 2011

Spring meet CDI, CDI meet Spring

I got the CDI to Spring Bridge working on Monday.
I got some design help from (Caucho) Resin's core engineering team on Monday to get an initial design and ideas for going from Spring to CDI .
(The other Direction!)
Today I got Spring to CDI integration working with Weld. It should also work with Resin 4.0.17 or Resin 4.0.18.

You can see the code at:


The tests are at:


This was really fun to write.

The CDI to Spring Bridge was easy and it was similar to something I wrote before for Presto (a precursor to Crank).
The Spring to CDi was much more difficult. It currently only works with Weld. It will work with Resin in the 4.0.17 release (likely).

This class does the CDI to Spring bridge:


This class does the Spring to CDI bridge.


This roo based webapp/project uses the CDI to Spring Bridge (it runs in Resin and should run in any CDI compliant app server Glassfish, JBoss, etc.):


Come fork it on github!



  1. Hi Rick, your Spring CDI bridge requires @Spring annotation usage :
    @Inject @Spring(name="fooBar")
    FooSpringBean springBean;

    Couldn't you make it work with just @Inject annotation ?
    Just like :
    FooSpringBean springBean;

    I think, this would be clearer.

  2. Hi Rick,

    Thanks a lot for your suggestions. I tried it out and allways get the error:

    org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [LicenceService] with qualifiers [@Spring] at injection point [[field] @Spring @Inject private ch.finaware.web.licence.LicenceActionManager.licenceService]

    When I try to annotate my cdi beans members as spring beans:

    public class LicenceActionManager implements Serializable {
    /** serialVersionUID */
    private static final long serialVersionUID = 6477324059536501069L;

    @Inject @Spring (type=LicenceService.class)
    private LicenceService licenceService;

    The weld can not handle the situation, when it does not know in advance, where to get the bean from. What are I'm doing wrong?

  3. jeje, ricky I've solved the problem:

    the springbridge misses the registrtion of it's extension! I've created the file: javax.enterprise.inject.spi.Extension under META-INF/services with the content: org.cdisource.springintegration.SpringIntegrationExtention and now everything works perfect.

    Thankts ricky and fix the problem

    Regards Michael


Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training