You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by moraleslos <mo...@hotmail.com> on 2006/12/05 20:05:51 UTC

SMX and multiple spring contexts

I have multiple Spring contexts used for maintaining my service mechanisms
and would like to know how to incorporate them into the SMX-mix of things. 
For example, I have a JBI unit that unmarshals xml data into POJOs.  This
flow is all defined in my servicemix.xml.  Now in my unmarshaller, I would
like to invoke a service that will process these populated POJOs.  The
service definitions are defined in a separate appContext.xml file.  So how
can I inject my services into the unmarshaller which is managed by SMX? 


servicemix.xml:
--------------------
......
<sm:activationSpec componentName="pojoUnmarshaller"
service="foo:pojoUnmarshaller">
<sm:component>
<bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
 </bean>
 </sm:component>
</sm:activationSpec>		
.....
--------------------


TestPojoUnmarshaller.java
------------------------------
...
private ProcessPojoService service;

public void setProcessPojoService( ProcessPojoService service) {
this.service = service;
}

public void process(MessageExchange exchange, NormalizedMessage message) {
   .... // do some unmarshalling
   Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
   service.processPojo(data);
   ...
}
---------------------------


appContext.xml
----------------------------
<beans 
	xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
       http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
.....
----------------------------------


Now how do I combine everything above so that I can inject my PojoService
into the Unmarshaller (which is managed by SMX) using an external Spring
configuration file (not part of servicemix.xml)?  Thanks in advance.

-los
-- 
View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7705641
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: SMX and multiple spring contexts

Posted by Bruce Snyder <br...@gmail.com>.
On 12/6/06, moraleslos <mo...@hotmail.com> wrote:
>
> The imported contexts are pure Spring contexts and there is no such thing as
> a <classpath> element-- here's the dtd:
> http://static.springframework.org/spring/docs/2.0.x/reference/springbeansdtd.html

The context files in ServiceMix are processed by the XBean-Spring
module  (http://geronimo.apache.org/xbean) which is built on top of
Spring and it does support a classpath element.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/

Re: SMX and multiple spring contexts

Posted by moraleslos <mo...@hotmail.com>.
The imported contexts are pure Spring contexts and there is no such thing as
a <classpath> element-- here's the dtd: 
http://static.springframework.org/spring/docs/2.0.x/reference/springbeansdtd.html

-los


gnodet wrote:
> 
> AFAIK, the classpath should be preprocessed first, but it may not be
> set correctly when the imported context is loaded.
> Have you tried putting the classpath tag in the imported context ?
> 
> On 12/6/06, moraleslos <mo...@hotmail.com> wrote:
>>
>> I'm running into dependency issues when doing this.  Seems like the
>> <import
>> resource...> imports the Spring contexts and tries to load the beans up
>> first before continuing with the jbi-based dependencies.  Basically in my
>> Spring context contains a bean for a service POJO which utilizes
>> Hibernate.
>> I have the Hibernate jar defined in servicemix.xml like this:
>>
>> <import resource=classpath:appContext.xml/>
>>
>> <classpath>
>> <location>lib/hibernate-3.2.1.ga.jar</location>
>> ...
>> </classpath>
>>
>> However, seems like it tries to find Hibernate dependencies needed
>> implicitly by my appContext.xml before ever reaching the classpath
>> dependencies.  I had to explicitly put the hibernate jar into SMX's
>> /lib/optional directory to make everything nice and neat.  Is there a way
>> to
>> make it work w/o putting the jar into SMX's lib/optional directory?
>>
>> -los
>>
>>
>> gnodet wrote:
>> >
>> > Take a look at the main servicemix.xml in the distribution.
>> > It uses <import> tags to load other spring configuration files.
>> > Like this one:
>> >   <import resource="classpath:security.xml" />
>> >
>> >
>> > On 12/5/06, moraleslos <mo...@hotmail.com> wrote:
>> >>
>> >> I have multiple Spring contexts used for maintaining my service
>> >> mechanisms
>> >> and would like to know how to incorporate them into the SMX-mix of
>> >> things.
>> >> For example, I have a JBI unit that unmarshals xml data into POJOs. 
>> This
>> >> flow is all defined in my servicemix.xml.  Now in my unmarshaller, I
>> >> would
>> >> like to invoke a service that will process these populated POJOs.  The
>> >> service definitions are defined in a separate appContext.xml file.  So
>> >> how
>> >> can I inject my services into the unmarshaller which is managed by
>> SMX?
>> >>
>> >>
>> >> servicemix.xml:
>> >> --------------------
>> >> ......
>> >> <sm:activationSpec componentName="pojoUnmarshaller"
>> >> service="foo:pojoUnmarshaller">
>> >> <sm:component>
>> >> <bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
>> >>  </bean>
>> >>  </sm:component>
>> >> </sm:activationSpec>
>> >> .....
>> >> --------------------
>> >>
>> >>
>> >> TestPojoUnmarshaller.java
>> >> ------------------------------
>> >> ...
>> >> private ProcessPojoService service;
>> >>
>> >> public void setProcessPojoService( ProcessPojoService service) {
>> >> this.service = service;
>> >> }
>> >>
>> >> public void process(MessageExchange exchange, NormalizedMessage
>> message)
>> >> {
>> >>    .... // do some unmarshalling
>> >>    Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
>> >>    service.processPojo(data);
>> >>    ...
>> >> }
>> >> ---------------------------
>> >>
>> >>
>> >> appContext.xml
>> >> ----------------------------
>> >> <beans
>> >>         xmlns="http://www.springframework.org/schema/beans"
>> >>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> >>     xmlns:aop="http://www.springframework.org/schema/aop"
>> >>     xmlns:tx="http://www.springframework.org/schema/tx"
>> >>     xsi:schemaLocation="
>> >>        http://www.springframework.org/schema/beans
>> >> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>> >>        http://www.springframework.org/schema/tx
>> >> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
>> >>        http://www.springframework.org/schema/aop
>> >> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>> >>
>> >> <bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
>> >> .....
>> >> ----------------------------------
>> >>
>> >>
>> >> Now how do I combine everything above so that I can inject my
>> PojoService
>> >> into the Unmarshaller (which is managed by SMX) using an external
>> Spring
>> >> configuration file (not part of servicemix.xml)?  Thanks in advance.
>> >>
>> >> -los
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7705641
>> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Cheers,
>> > Guillaume Nodet
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7724766
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> 
> 

-- 
View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7732971
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: SMX and multiple spring contexts

Posted by Guillaume Nodet <gn...@gmail.com>.
AFAIK, the classpath should be preprocessed first, but it may not be
set correctly when the imported context is loaded.
Have you tried putting the classpath tag in the imported context ?

On 12/6/06, moraleslos <mo...@hotmail.com> wrote:
>
> I'm running into dependency issues when doing this.  Seems like the <import
> resource...> imports the Spring contexts and tries to load the beans up
> first before continuing with the jbi-based dependencies.  Basically in my
> Spring context contains a bean for a service POJO which utilizes Hibernate.
> I have the Hibernate jar defined in servicemix.xml like this:
>
> <import resource=classpath:appContext.xml/>
>
> <classpath>
> <location>lib/hibernate-3.2.1.ga.jar</location>
> ...
> </classpath>
>
> However, seems like it tries to find Hibernate dependencies needed
> implicitly by my appContext.xml before ever reaching the classpath
> dependencies.  I had to explicitly put the hibernate jar into SMX's
> /lib/optional directory to make everything nice and neat.  Is there a way to
> make it work w/o putting the jar into SMX's lib/optional directory?
>
> -los
>
>
> gnodet wrote:
> >
> > Take a look at the main servicemix.xml in the distribution.
> > It uses <import> tags to load other spring configuration files.
> > Like this one:
> >   <import resource="classpath:security.xml" />
> >
> >
> > On 12/5/06, moraleslos <mo...@hotmail.com> wrote:
> >>
> >> I have multiple Spring contexts used for maintaining my service
> >> mechanisms
> >> and would like to know how to incorporate them into the SMX-mix of
> >> things.
> >> For example, I have a JBI unit that unmarshals xml data into POJOs.  This
> >> flow is all defined in my servicemix.xml.  Now in my unmarshaller, I
> >> would
> >> like to invoke a service that will process these populated POJOs.  The
> >> service definitions are defined in a separate appContext.xml file.  So
> >> how
> >> can I inject my services into the unmarshaller which is managed by SMX?
> >>
> >>
> >> servicemix.xml:
> >> --------------------
> >> ......
> >> <sm:activationSpec componentName="pojoUnmarshaller"
> >> service="foo:pojoUnmarshaller">
> >> <sm:component>
> >> <bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
> >>  </bean>
> >>  </sm:component>
> >> </sm:activationSpec>
> >> .....
> >> --------------------
> >>
> >>
> >> TestPojoUnmarshaller.java
> >> ------------------------------
> >> ...
> >> private ProcessPojoService service;
> >>
> >> public void setProcessPojoService( ProcessPojoService service) {
> >> this.service = service;
> >> }
> >>
> >> public void process(MessageExchange exchange, NormalizedMessage message)
> >> {
> >>    .... // do some unmarshalling
> >>    Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
> >>    service.processPojo(data);
> >>    ...
> >> }
> >> ---------------------------
> >>
> >>
> >> appContext.xml
> >> ----------------------------
> >> <beans
> >>         xmlns="http://www.springframework.org/schema/beans"
> >>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >>     xmlns:aop="http://www.springframework.org/schema/aop"
> >>     xmlns:tx="http://www.springframework.org/schema/tx"
> >>     xsi:schemaLocation="
> >>        http://www.springframework.org/schema/beans
> >> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
> >>        http://www.springframework.org/schema/tx
> >> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
> >>        http://www.springframework.org/schema/aop
> >> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
> >>
> >> <bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
> >> .....
> >> ----------------------------------
> >>
> >>
> >> Now how do I combine everything above so that I can inject my PojoService
> >> into the Unmarshaller (which is managed by SMX) using an external Spring
> >> configuration file (not part of servicemix.xml)?  Thanks in advance.
> >>
> >> -los
> >> --
> >> View this message in context:
> >> http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7705641
> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> >
> >
>
> --
> View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7724766
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet

Re: SMX and multiple spring contexts

Posted by moraleslos <mo...@hotmail.com>.
I'm running into dependency issues when doing this.  Seems like the <import
resource...> imports the Spring contexts and tries to load the beans up
first before continuing with the jbi-based dependencies.  Basically in my
Spring context contains a bean for a service POJO which utilizes Hibernate. 
I have the Hibernate jar defined in servicemix.xml like this:

<import resource=classpath:appContext.xml/>

<classpath>
<location>lib/hibernate-3.2.1.ga.jar</location>
...
</classpath>

However, seems like it tries to find Hibernate dependencies needed
implicitly by my appContext.xml before ever reaching the classpath
dependencies.  I had to explicitly put the hibernate jar into SMX's
/lib/optional directory to make everything nice and neat.  Is there a way to
make it work w/o putting the jar into SMX's lib/optional directory?

-los


gnodet wrote:
> 
> Take a look at the main servicemix.xml in the distribution.
> It uses <import> tags to load other spring configuration files.
> Like this one:
>   <import resource="classpath:security.xml" />
> 
> 
> On 12/5/06, moraleslos <mo...@hotmail.com> wrote:
>>
>> I have multiple Spring contexts used for maintaining my service
>> mechanisms
>> and would like to know how to incorporate them into the SMX-mix of
>> things.
>> For example, I have a JBI unit that unmarshals xml data into POJOs.  This
>> flow is all defined in my servicemix.xml.  Now in my unmarshaller, I
>> would
>> like to invoke a service that will process these populated POJOs.  The
>> service definitions are defined in a separate appContext.xml file.  So
>> how
>> can I inject my services into the unmarshaller which is managed by SMX?
>>
>>
>> servicemix.xml:
>> --------------------
>> ......
>> <sm:activationSpec componentName="pojoUnmarshaller"
>> service="foo:pojoUnmarshaller">
>> <sm:component>
>> <bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
>>  </bean>
>>  </sm:component>
>> </sm:activationSpec>
>> .....
>> --------------------
>>
>>
>> TestPojoUnmarshaller.java
>> ------------------------------
>> ...
>> private ProcessPojoService service;
>>
>> public void setProcessPojoService( ProcessPojoService service) {
>> this.service = service;
>> }
>>
>> public void process(MessageExchange exchange, NormalizedMessage message)
>> {
>>    .... // do some unmarshalling
>>    Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
>>    service.processPojo(data);
>>    ...
>> }
>> ---------------------------
>>
>>
>> appContext.xml
>> ----------------------------
>> <beans
>>         xmlns="http://www.springframework.org/schema/beans"
>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>     xmlns:aop="http://www.springframework.org/schema/aop"
>>     xmlns:tx="http://www.springframework.org/schema/tx"
>>     xsi:schemaLocation="
>>        http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>>        http://www.springframework.org/schema/tx
>> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
>>        http://www.springframework.org/schema/aop
>> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>>
>> <bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
>> .....
>> ----------------------------------
>>
>>
>> Now how do I combine everything above so that I can inject my PojoService
>> into the Unmarshaller (which is managed by SMX) using an external Spring
>> configuration file (not part of servicemix.xml)?  Thanks in advance.
>>
>> -los
>> --
>> View this message in context:
>> http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7705641
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> 
> 

-- 
View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7724766
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: SMX and multiple spring contexts

Posted by Guillaume Nodet <gn...@gmail.com>.
Take a look at the main servicemix.xml in the distribution.
It uses <import> tags to load other spring configuration files.
Like this one:
  <import resource="classpath:security.xml" />


On 12/5/06, moraleslos <mo...@hotmail.com> wrote:
>
> I have multiple Spring contexts used for maintaining my service mechanisms
> and would like to know how to incorporate them into the SMX-mix of things.
> For example, I have a JBI unit that unmarshals xml data into POJOs.  This
> flow is all defined in my servicemix.xml.  Now in my unmarshaller, I would
> like to invoke a service that will process these populated POJOs.  The
> service definitions are defined in a separate appContext.xml file.  So how
> can I inject my services into the unmarshaller which is managed by SMX?
>
>
> servicemix.xml:
> --------------------
> ......
> <sm:activationSpec componentName="pojoUnmarshaller"
> service="foo:pojoUnmarshaller">
> <sm:component>
> <bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
>  </bean>
>  </sm:component>
> </sm:activationSpec>
> .....
> --------------------
>
>
> TestPojoUnmarshaller.java
> ------------------------------
> ...
> private ProcessPojoService service;
>
> public void setProcessPojoService( ProcessPojoService service) {
> this.service = service;
> }
>
> public void process(MessageExchange exchange, NormalizedMessage message) {
>    .... // do some unmarshalling
>    Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
>    service.processPojo(data);
>    ...
> }
> ---------------------------
>
>
> appContext.xml
> ----------------------------
> <beans
>         xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns:aop="http://www.springframework.org/schema/aop"
>     xmlns:tx="http://www.springframework.org/schema/tx"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>        http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
>        http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>
> <bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
> .....
> ----------------------------------
>
>
> Now how do I combine everything above so that I can inject my PojoService
> into the Unmarshaller (which is managed by SMX) using an external Spring
> configuration file (not part of servicemix.xml)?  Thanks in advance.
>
> -los
> --
> View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7705641
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet

Re: SMX and multiple spring contexts

Posted by moraleslos <mo...@hotmail.com>.
Well, I'm not sure if I want to convert my pure Spring 2.0 context files into
xbean-spring files which requires another dependency (xbean-spring.jar)
since if I choose to have these app contexts run outside of smx, I don't
really have to change a thing.  Maybe this is a bug with xbean?  I was
thinking that the <classpath>s would be looked upon first before anything
else happens (i.e. before processing <import resource...).  Is there another
way around this?

-los


moraleslos wrote:
> 
> I have multiple Spring contexts used for maintaining my service mechanisms
> and would like to know how to incorporate them into the SMX-mix of things. 
> For example, I have a JBI unit that unmarshals xml data into POJOs.  This
> flow is all defined in my servicemix.xml.  Now in my unmarshaller, I would
> like to invoke a service that will process these populated POJOs.  The
> service definitions are defined in a separate appContext.xml file.  So how
> can I inject my services into the unmarshaller which is managed by SMX? 
> 
> 
> servicemix.xml:
> --------------------
> ......
> <sm:activationSpec componentName="pojoUnmarshaller"
> service="foo:pojoUnmarshaller">
> <sm:component>
> <bean class="com.test.servicemix.integration.TestPojoUnmarshaller">
>  </bean>
>  </sm:component>
> </sm:activationSpec>		
> .....
> --------------------
> 
> 
> TestPojoUnmarshaller.java
> ------------------------------
> ...
> private ProcessPojoService service;
> 
> public void setProcessPojoService( ProcessPojoService service) {
> this.service = service;
> }
> 
> public void process(MessageExchange exchange, NormalizedMessage message) {
>    .... // do some unmarshalling
>    Pojo data = (Pojo)unmarshaller.unmarshal(inputstream);
>    service.processPojo(data);
>    ...
> }
> ---------------------------
> 
> 
> appContext.xml
> ----------------------------
> <beans 
> 	xmlns="http://www.springframework.org/schema/beans"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns:aop="http://www.springframework.org/schema/aop"
>     xmlns:tx="http://www.springframework.org/schema/tx"
>     xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>        http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
>        http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
> 
> <bean id="pojoService" class="com.test.service.PojoServiceImpl"/>
> .....
> ----------------------------------
> 
> 
> Now how do I combine everything above so that I can inject my PojoService
> into the Unmarshaller (which is managed by SMX) using an external Spring
> configuration file (not part of servicemix.xml)?  Thanks in advance.
> 
> -los
> 

-- 
View this message in context: http://www.nabble.com/SMX-and-multiple-spring-contexts-tf2763562s12049.html#a7739693
Sent from the ServiceMix - User mailing list archive at Nabble.com.