You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Andrea Zoppello <zo...@tiscali.it> on 2008/04/09 14:14:23 UTC

Lightweight 2 SM Bean - Problems with resource injection??

Hi,

I've start to work to port the features of Lw-container pojo to sm bean, 
but i've
find a problem.

I've developed and deployed a simple process containing a simple Bean where
i've used the following syntax:

@Resource
   private DeliveryChannel channel;

to get the channel injected to my pojo

The code of the onMessage method looks like:

public void onMessageExchange(MessageExchange exchange)
           throws MessagingException {
       if (channel == null){
           System.out.println(" **************** Channel is null 
****************");
       }else{
            System.out.println(" **************** Channel is not null 
****************");
       }
}


I've no problem to deploy this, the problem is that the channel is 
always null, it means it's not
injected correctly.

Any Idea on that??

Re: Lightweight 2 SM Bean - Problems with resource injection??

Posted by Andrea Zoppello <zo...@tiscali.it>.
Definitely yes!!!

The possible solution are two:

1) Copy the geronimo_annotations.jar in the \SMX_HOME\lib where you've 
put the jar containing the
bean class.

2) Put the jar containing the bean, in the service unit so the 
classloader for both bean and resource is the
su classloader

The first one fits better my requirements beacuse i don't want the code 
generators for pojo bean take care of
which jar to include in the su, but all the solutions are quite good.

Andrea


Guillaume Nodet ha scritto:
> I guess the problem is then that the annotation will not be available from
> the classloader that loads your class.  You should try putting the
> commons-annotation jar in the container classpath then.
>
> On Wed, Apr 9, 2008 at 2:31 PM, Andrea Zoppello <zo...@tiscali.it> wrote:
>
>   
>> Hi,
>>
>> In previous post i miss to say that the jar containing the bean class is
>> not in the su, but in servicemix classpath.
>>
>> Is this a problem??
>>
>> With the old lw-container this was not a problem...
>>
>> Andrea
>>
>> Guillaume Nodet ha scritto:
>>
>>  Can you check that your SU does not include the common-annotation jar
>>     
>>> wich
>>> includes the @Resource annotation ?
>>> If it does, there will be a problem where the two annotations won't be
>>> from
>>> the same classloader and the component will not recognize it, hence no
>>> injection will occur.
>>> Other than that, I've no clear idea why it would not work.
>>>
>>> On Wed, Apr 9, 2008 at 2:14 PM, Andrea Zoppello <zo...@tiscali.it>
>>> wrote:
>>>
>>>
>>>
>>>       
>>>> Hi,
>>>>
>>>> I've start to work to port the features of Lw-container pojo to sm
>>>> bean,
>>>> but i've
>>>> find a problem.
>>>>
>>>> I've developed and deployed a simple process containing a simple Bean
>>>> where
>>>> i've used the following syntax:
>>>>
>>>> @Resource
>>>>  private DeliveryChannel channel;
>>>>
>>>> to get the channel injected to my pojo
>>>>
>>>> The code of the onMessage method looks like:
>>>>
>>>> public void onMessageExchange(MessageExchange exchange)
>>>>         throws MessagingException {
>>>>     if (channel == null){
>>>>         System.out.println(" **************** Channel is null
>>>> ****************");
>>>>     }else{
>>>>          System.out.println(" **************** Channel is not null
>>>> ****************");
>>>>     }
>>>> }
>>>>
>>>>
>>>> I've no problem to deploy this, the problem is that the channel is
>>>> always
>>>> null, it means it's not
>>>> injected correctly.
>>>>
>>>> Any Idea on that??
>>>>
>>>>
>>>>
>>>>         
>>>
>>>
>>>
>>>       
>>     
>
>
>   


Re: Lightweight 2 SM Bean - Problems with resource injection??

Posted by Guillaume Nodet <gn...@gmail.com>.
I guess the problem is then that the annotation will not be available from
the classloader that loads your class.  You should try putting the
commons-annotation jar in the container classpath then.

On Wed, Apr 9, 2008 at 2:31 PM, Andrea Zoppello <zo...@tiscali.it> wrote:

> Hi,
>
> In previous post i miss to say that the jar containing the bean class is
> not in the su, but in servicemix classpath.
>
> Is this a problem??
>
> With the old lw-container this was not a problem...
>
> Andrea
>
> Guillaume Nodet ha scritto:
>
>  Can you check that your SU does not include the common-annotation jar
> > wich
> > includes the @Resource annotation ?
> > If it does, there will be a problem where the two annotations won't be
> > from
> > the same classloader and the component will not recognize it, hence no
> > injection will occur.
> > Other than that, I've no clear idea why it would not work.
> >
> > On Wed, Apr 9, 2008 at 2:14 PM, Andrea Zoppello <zo...@tiscali.it>
> > wrote:
> >
> >
> >
> > > Hi,
> > >
> > > I've start to work to port the features of Lw-container pojo to sm
> > > bean,
> > > but i've
> > > find a problem.
> > >
> > > I've developed and deployed a simple process containing a simple Bean
> > > where
> > > i've used the following syntax:
> > >
> > > @Resource
> > >  private DeliveryChannel channel;
> > >
> > > to get the channel injected to my pojo
> > >
> > > The code of the onMessage method looks like:
> > >
> > > public void onMessageExchange(MessageExchange exchange)
> > >         throws MessagingException {
> > >     if (channel == null){
> > >         System.out.println(" **************** Channel is null
> > > ****************");
> > >     }else{
> > >          System.out.println(" **************** Channel is not null
> > > ****************");
> > >     }
> > > }
> > >
> > >
> > > I've no problem to deploy this, the problem is that the channel is
> > > always
> > > null, it means it's not
> > > injected correctly.
> > >
> > > Any Idea on that??
> > >
> > >
> > >
> >
> >
> >
> >
> >
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Lightweight 2 SM Bean - Problems with resource injection??

Posted by Andrea Zoppello <zo...@tiscali.it>.
Hi,

In previous post i miss to say that the jar containing the bean class is
not in the su, but in servicemix classpath.

Is this a problem??

With the old lw-container this was not a problem...

Andrea

Guillaume Nodet ha scritto:
> Can you check that your SU does not include the common-annotation jar wich
> includes the @Resource annotation ?
> If it does, there will be a problem where the two annotations won't be from
> the same classloader and the component will not recognize it, hence no
> injection will occur.
> Other than that, I've no clear idea why it would not work.
>
> On Wed, Apr 9, 2008 at 2:14 PM, Andrea Zoppello <zo...@tiscali.it> wrote:
>
>   
>> Hi,
>>
>> I've start to work to port the features of Lw-container pojo to sm bean,
>> but i've
>> find a problem.
>>
>> I've developed and deployed a simple process containing a simple Bean
>> where
>> i've used the following syntax:
>>
>> @Resource
>>  private DeliveryChannel channel;
>>
>> to get the channel injected to my pojo
>>
>> The code of the onMessage method looks like:
>>
>> public void onMessageExchange(MessageExchange exchange)
>>          throws MessagingException {
>>      if (channel == null){
>>          System.out.println(" **************** Channel is null
>> ****************");
>>      }else{
>>           System.out.println(" **************** Channel is not null
>> ****************");
>>      }
>> }
>>
>>
>> I've no problem to deploy this, the problem is that the channel is always
>> null, it means it's not
>> injected correctly.
>>
>> Any Idea on that??
>>
>>     
>
>
>
>   


Re: Lightweight 2 SM Bean - Problems with resource injection??

Posted by Guillaume Nodet <gn...@gmail.com>.
Can you check that your SU does not include the common-annotation jar wich
includes the @Resource annotation ?
If it does, there will be a problem where the two annotations won't be from
the same classloader and the component will not recognize it, hence no
injection will occur.
Other than that, I've no clear idea why it would not work.

On Wed, Apr 9, 2008 at 2:14 PM, Andrea Zoppello <zo...@tiscali.it> wrote:

> Hi,
>
> I've start to work to port the features of Lw-container pojo to sm bean,
> but i've
> find a problem.
>
> I've developed and deployed a simple process containing a simple Bean
> where
> i've used the following syntax:
>
> @Resource
>  private DeliveryChannel channel;
>
> to get the channel injected to my pojo
>
> The code of the onMessage method looks like:
>
> public void onMessageExchange(MessageExchange exchange)
>          throws MessagingException {
>      if (channel == null){
>          System.out.println(" **************** Channel is null
> ****************");
>      }else{
>           System.out.println(" **************** Channel is not null
> ****************");
>      }
> }
>
>
> I've no problem to deploy this, the problem is that the channel is always
> null, it means it's not
> injected correctly.
>
> Any Idea on that??
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/