I feel silly. I just came up with a way to do what I want in pure spring. The
solution I was proposing with CamelContextFactoryBean, doesn't actually use
any aspect of the Camel code. You can attach an AC to a new parent in
standalone code, like so:
-------------------------------------
package utility.spring;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
public class ParentInjector implements ApplicationContextAware {
ConfigurableApplicationContext applicationContext;
ApplicationContext parentApplicationContext;
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
if ( (ConfigurableApplicationContext.class).isAssignableFrom(
applicationContext.getClass() ) ) {
this.applicationContext =
(ConfigurableApplicationContext)applicationContext;
attachParent();
} else {
throw new BeanNotOfRequiredTypeException("<ApplicationContext>",
ConfigurableApplicationContext.class, applicationContext.getClass());
}
}
public void setParentApplicationContext(ApplicationContext
parentApplicationContext) throws BeansException {
this.parentApplicationContext = parentApplicationContext;
attachParent();
}
private void attachParent() {
if (applicationContext != null && parentApplicationContext !=null)
applicationContext.setParent(parentApplicationContext);
}
}
-------------------------------------
Then in ANY xml based config file, you can add a bean like so
-------------------------------------
<bean class="utility.spring.ParentInjector">
<property name="parentApplicationContext">
<bean class="utility.spring.MyFavSpringLocatorOrFactory"
factory-method="getApplicationContext">
<constructor-arg value="theNameOfMyContext"/>
</bean>
</property>
</bean>
-------------------------------------
Where utility.spring.MyFavSpringLocatorOrFactory is a class that locates,
builds, borrows, or steals an ApplicationContext object in any fashion it
pleases, xml based or not.
James.Strachan wrote:
BTW I'm still not quite sure why you couldn't just have this inside
activemq.xml
<include uri="myroutes.xml"/>
then in myroutes.xml have a <camelContext> and whatever other routes you
want?
For example, suppose I want to make a message enricher, and my route will be
something like:
from(activemq:inbox).to("enricher").to(activemq:outbox);
Suppose the "enricher" bean is a camel Processor that will delegate to a
bunch of preexisting beans, like my data access layer, defined in some
ApplicationContext that is not 100% XML based. Maybe we used the grails
spring builder or spring's java config for all or part of it. Maybe I have
mostly XML, except that I do a little bit with java code that uses Spring
APIs to manipulate the AC before it's offered up for consumption. Maybe I'm
constructing my AC dynamically from a registry using mule's
GalaxyApplicationContext.
I could port the "enricher" bean to an XML config, but I'd have to do so for
it and all it's bean dependencies, which might be hard to accomplish. If I
succeed, then I'm double maintaining them, violating DRY. It might not even
be possible to know what the dependencies are: if I use something like a
strategy pattern with <property name="strategy"
value="${strategy.impl.bean.name}" , a plugin system, or a registry
indirection like GalaxyApplicationContext, they could be changing without my
control.