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:
https://github.com/CDISource/cdisource/blob/master/spring/src/main/java/org/cdisource/springintegration/SpringIntegrationExtention.java
The tests are at:
https://github.com/CDISource/cdisource/tree/master/spring/src/test/java/org/cdisource/springintegration
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:
https://github.com/CDISource/cdisource/blob/master/spring/src/main/java/org/cdisource/springintegration/CdiBeanFactoryPostProcessor.java
This class does the Spring to CDI bridge.
https://github.com/CDISource/cdisource/blob/master/spring/src/main/java/org/cdisource/springintegration/SpringIntegrationExtention.java
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.):
https://github.com/CDISource/examples/tree/master/spring-integration-example
Come fork it on github!
https://github.com/CDISource/cdisource
;)
ReplyDeleteHi Rick, your Spring CDI bridge requires @Spring annotation usage :
ReplyDelete@Inject @Spring(name="fooBar")
FooSpringBean springBean;
Couldn't you make it work with just @Inject annotation ?
Just like :
@Inject
FooSpringBean springBean;
I think, this would be clearer.
Hi Rick,
ReplyDeleteThanks 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:
@Named("licenceActionManager")
@ApplicationScoped
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?
jeje, ricky I've solved the problem:
ReplyDeletethe 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