You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hugo <th...@voila.fr> on 2012/04/16 16:18:08 UTC

Spring context and camel context in the same time

Hello everyone,

Is it possible to use a camel context and a spring context (more precisely
an AnnotationConfigApplicationContext) in a same application ?

I explained myself : I'm trying to do 2 "simple" things.
- get beans (created by spring through the annotation @Named) file from a
java class (without injection) 
- scan packages to create beans from annotation (@Named)

I am not achieving do that neither using <context:component-scan base.../>
neither creating a new spring context...

I would like to create something like that (in addition of the existing
camelcontext defined in the xml file camel-context.xml) :

public MyClass {
  AnnotationConfigApplicationContext currentApplicationContext = new
AnnotationConfigApplicationContext();
  currentApplicationContext.register(BeanSpring.class);
  currentApplicationContext.refresh();
}

and my config file :

@Configuration
@ComponentScan("com.francetelecom.prototyperoutes")
public class BeanSpring {

	String MANDATORY_PROFILE = "test";
	
	String getProp() {
		return MANDATORY_PROFILE;
	}
}

In my xml, I've just got :

  <bean id="prototypeRoutes"
class="com.francetelecom.prototyperoutes.PrototypeRoutes"/>

  <camel:camelContext id="camel">
    <camel:routeBuilder ref="prototypeRoutes"/>
  </camel:camelContext>



--
View this message in context: http://camel.465427.n5.nabble.com/Spring-context-and-camel-context-in-the-same-time-tp5643943p5643943.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Spring context and camel context in the same time

Posted by Claus Ibsen <cl...@gmail.com>.
The XML file is just a standard Spring XML file.
So whatever Spring supports to use both its annotation and to load
beans from a XML file, that is your answer.

You can also create a SpringCamelContext yourself from Java code, to
get Camel. Then you may not need the XML file.


On Mon, Apr 16, 2012 at 4:18 PM, Hugo <th...@voila.fr> wrote:
> Hello everyone,
>
> Is it possible to use a camel context and a spring context (more precisely
> an AnnotationConfigApplicationContext) in a same application ?
>
> I explained myself : I'm trying to do 2 "simple" things.
> - get beans (created by spring through the annotation @Named) file from a
> java class (without injection)
> - scan packages to create beans from annotation (@Named)
>
> I am not achieving do that neither using <context:component-scan base.../>
> neither creating a new spring context...
>
> I would like to create something like that (in addition of the existing
> camelcontext defined in the xml file camel-context.xml) :
>
> public MyClass {
>  AnnotationConfigApplicationContext currentApplicationContext = new
> AnnotationConfigApplicationContext();
>  currentApplicationContext.register(BeanSpring.class);
>  currentApplicationContext.refresh();
> }
>
> and my config file :
>
> @Configuration
> @ComponentScan("com.francetelecom.prototyperoutes")
> public class BeanSpring {
>
>        String MANDATORY_PROFILE = "test";
>
>        String getProp() {
>                return MANDATORY_PROFILE;
>        }
> }
>
> In my xml, I've just got :
>
>  <bean id="prototypeRoutes"
> class="com.francetelecom.prototyperoutes.PrototypeRoutes"/>
>
>  <camel:camelContext id="camel">
>    <camel:routeBuilder ref="prototypeRoutes"/>
>  </camel:camelContext>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Spring-context-and-camel-context-in-the-same-time-tp5643943p5643943.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/