I’ve been playing around with Mule lately, mostly just trying to learn and see if it’d be a fit for a little side project I’m working on (it looks like it won’t, but that’s OK). But one thing that was a bit confusing about Mule integration is that the 2.0 version is very heavily dependent on Spring. That would be nice if I used Spring, but this project uses Guice.
First I tried Google, but only came up with this. Then I tried to see how other containers (Pico, Hivemind, etc) integrated in to Mule, but it turns out those integrations were for 1.x and nothing has been built for 2.x. I’m sure there is a better solution that what I came up with, but for a quick and dirty integration this worked really well:
<spring:bean name="foo" class="com.bar.GuiceUtil"
factory-method="getGuiceInstance">
<spring:constructor-arg>
<spring:value>com.bar.Foo</spring:value>
</spring:constructor-arg>
</spring:bean>
<model name="...">
<service name="...">
<inbound>
<inbound-endpoint address="..." />
</inbound>
<component>
<spring-object bean="foo"/>
</component>
</service>
</model>
Basically, you just make a simple utility class (GuiceUtil) that holds your Guice Injector and offers a static method named getGuiceInstace:
public static <T> T getGuiceInstance(Class<T> t) {
return injector.getInstance(t);
}
Now Spring is configured to created a Spring bean named “foo” that actually came from Guice. Then you simply tell Mule to use that Spring bean. I’m sure there are a lot better ways to do this (I am a complete Mule newbie and know very little of the configuration options), but this got the job done for me.
on Aug 24th, 2008 at 4:27 pm
Hmmm… interesting Pat, I wonder what are you doing with those code, integration I mean. Any new ideas you are working on? Or just playing around with some interesting stuff
on Sep 3rd, 2008 at 10:48 pm
Hey Patrick,
The way to do it in Mule 2.0 is to introduce a GuiceRegistry which is responsible for looking after loading the Guice objects and passing lifecycle events to the Guice container. now your objects can be referenced in other places in Mule Xml.
I should also note that only the Xml configuration in Mule requires Spring, the core and all other modules/transports do not depend on spring if not using Xml to configure Mule.
on Dec 5th, 2008 at 2:19 am
[...] public links >> guice Using Guice and Mule Together Saved by rasweiler on Fri 14-11-2008 Google Guice- Agile Lightweight Dependency Injection [...]