Recently I tried to expose a Spring AOP proxy bean as a web service .but it gave some byte code loading problems with CGLIB. But with a small change I got the result. If we follow the best practices like separation of service contract and implementation (as a Java Interface and Implementation Class), we can apply such improvements very easily.
I used Axis2 inside a Spring based web application (within a WAR file) approach.
This is the Spring application context file as you can see there is no any magic in the code it just use the features of new spring 2 schema to convert a POJO as an Aspect.
<bean id="myService" class="my.MyService"/> <bean id="profiler" class="my.SimpleProfiler"/> <aop:config> <aop:aspect ref="profiler"> <aop:pointcut id="allServiceMethods" expression="execution( * my..*.*(..))"/> <aop:around pointcut-ref="allServiceMethods" method="doBasicProfiling"/> </aop:aspect> </aop:config>
The key is ServiceClass parameter in the service.xml file where you have to specify your service contract (Java interface) instead of implementation class, the rest of the code is identical to the examples codes available in user guide.
<serviceGroup> <service name="MyService" > <parameter name="ServiceObjectSupplier" locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter> <parameter name="SpringBeanName" locked="false">myService</parameter> <parameter name="ServiceClass" locked="false">my.IMyService</parameter> <operation name="sayHi"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </operation> </service> </serviceGroup>本文转载自: http://ssagara.blogspot.com/2008/08/axis2-with-spring-aop.html