Hi Steven,

first of all, I have very little experience with Spring, but I know that other people are using it together with RIFE.

I want to do some more advanced dependency injection (DAOs and other service objects) so I started looking at Spring integration. I have some questions.

First, do I have a correct picture of how it works? (I will definitely put this on the Wiki; the page on Spring integration is tiny at the moment.)
  • RIFE is the outermost entity (that is, Spring is a service managed by RIFE, not the other way around).
That's not necessarily true, you can have both a RIFE and a Spring application running side-to-side in the same web application. If you use the ParticipantSpringWeb participant without a parameter, it will obtain the Spring BeanFactory from the web application context.
  • Each RIFE participant can supply values for properties that are declared in the site declaration or element declarations or wherever. The Spring participant simply supplies beans to RIFE based on the bean names.
Correct.
  • RIFE does the actual injection of values into elements and other RIFE-managed objects.
Only into elements atm.
  • Spring does the wiring of dependencies between Spring-managed beans; RIFE does no injection of values into objects Spring instantiates.
Correct.
  • It would be a bad idea to list the same object in both the Spring and the RIFE configuration since only one or the other would actually do any dependency injection.
Correct.
Assuming I'm correct about how it works, is the intended usage as follows if I want everything to be autowired as much as possible?
  • Declare all my service objects in Spring and let it wire them up.
  • Declare all my elements in the RIFE configuration as usual.
  • Also declare each service object in my RIFE site definition (so they don't have to be declared for individual elements). They are just declared as <property name="foobarService" />.
  • In my element classes, provide setters of compatible types for both the Spring beans and the RIFE-managed resources like Datasource objects.
Yes, that seems correct. Note that when you provide a value to a property you can use the <participant> tag to retrieve an object from the Spring participant.
And assuming I've got *that* more or less right, I am unclear on how to do one more thing: pass a RIFE-managed resource into the Spring world for autowiring. The simple example would be a DAO that uses RIFE's database APIs; I will need to use Spring to instantiate that DAO and wire it with other non-element objects, but the DAO needs to be injected with a Datasource object in order to use the RIFE APIs. How do I tell RIFE and Spring that there's this externally-supplied object that should be added to the autowiring mix?

The only clean solution I can think of is to write a factory class for the Spring side that does static method calls to grab a Datasource from RIFE. That seems wasteful, though -- there ought to be some way for RIFE to inject dependencies into Spring, since it has already made a Datasource for me.

I'm sorry, my Spring-foo is not good enough atm to be able to answer this correctly. Maybe this is something that you can also add to the initialize method overriding solution that I describe below.

What would be swell would be a Spring participant that automatically adds all the Spring beans to the list of global RIFE properties. That way you wouldn't have to list the beans in two places.

As long as Spring supports full introspection of the beans in the factory, that simply would be an extension of SpringWebParticipant. You can override the initialize() method. It's implementation would call parent.initialize() first and then you can use getRepository().getProperties() to obtain a handle on the global properties. These can then be filled in.

Hope this helps,

Geert

--
Geert Bevin 
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com


_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to