users@jersey.java.net

[Jersey] Re: Jersey and AOP

From: Samuel Liard <samuel_at_net-liard.com>
Date: Thu, 27 Jan 2011 09:24:59 +0100

Thanks a lot !

It's true, my service implement an interface.
And when I suppress this interface AOP work :)

Samuel

2011/1/27 Ryan :
> I'd guess your JAX-RS annotations are directly on your service class
> implementations and that said classes implement an interface. Spring AOP
> uses dynamic proxying for AOP by default for classes that implement an
> interface. See:
> http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html
> The problem you're experiencing is that the dynamic proxy becomes the bean
> used as the service, and when Jersey scans the beans looking for JAX-RS
> resource classes, it doesn't recognize it because your annotations are on
> your service class and not contained in the proxy, as the proxy is a
> separate object that just "wraps" your service, in a manner of speaking.
> There are at least a couple of options to fix this. You can move your JAX-RS
> annotations to the interface. You can add a separate class to act as the
> JAX-RS resource which is injected with and delegates to your service. You
> also might be able to configure Spring to prefer cglib proxies to dynamic
> proxies. It uses cglib proxies when you ask for Spring AOP on a class that
> implements no interfaces. A cglib proxy would work because it's actually a
> subclass of your class and would maintain the annotations.
> On Wed, Jan 26, 2011 at 10:23 AM, Samuel Liard <samuel_at_net-liard.com> wrote:
>>
>> Hi,
>>
>> I wrote a simple Jersey REST service with spring and hibernate.
>> All work fine before I add transaction management with aop.
>>
>> I just add :
>>  <tx:advice id="txAdvice" transaction-manager="transactionManager">
>>    <tx:attributes>
>>      <tx:method name="post"/>
>>      <tx:method name="*" read-only="true"/>
>>    </tx:attributes>
>>  </tx:advice>
>>
>>  <aop:config>
>>    <aop:pointcut id="fooServiceOperation" expression="execution(*
>> com.me.service.*.*(..))"/>
>>    <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
>>  </aop:config>
>>
>> And now I can't use my service :(
>> HTTP ERROR: 404
>> Not Found
>> RequestURI=/myproject/resources/myservice/
>>
>> Services outside the pointcut work.
>>
>> How do you configure your transaction ? Have you also some trouble
>> with Jersey and AOP ?
>>
>> Thanks
>>
>> Samuel
>
>