It has been one week now. I have tried to implement aop (spring aop and aspectj both) but with no success. I am able to get ejb proxy with spring context but not able to apply advices on it.
I have tried following xml config:
LCSession is remote interface and LCSessionBean in ejb implementation
1.
2.Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- target --> <bean id="lcBean" class="com.bnp.ivision.product.lc.sessionejb.LCSessionBean"> </bean> <!-- Advices --> <bean id="testAdvice" class="com.bnp.ivision.spring.TestAdvice"> </bean> <!-- Mapping: ProxyFactoryBean --> <!-- org.springframework.aop.framework.ProxyFactoryBean org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean --> <bean id="beanProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target" ref="slsbProxy"/> <property name="proxyInterfaces"> <list> <value>com.bnp.ivision.product.lc.sessionejb.LCSession</value> </list> </property> <property name="interceptorNames"> <list> <value>testAdvisor</value> </list> </property> </bean> <bean id="slsbProxy" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"> <property name="businessInterface" value="com.bnp.ivision.product.lc.sessionejb.LCSession"/> <property name="jndiName" value="LCSession"></property> </bean> <!-- NameMatchMethodPointcutAdvisor --> <bean id="testAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor"> <property name="advice" ref="testAdvice"/> </bean> </beans> package com.bnp.ivision.spring; import java.lang.reflect.Method; import org.springframework.aop.MethodBeforeAdvice; // MethodBeforeAdvice public class TestAdvice implements MethodBeforeAdvice{ public void before(Method method, Object[] args, Object target) throws Throwable { System.out.println("In before of " +method.getName()); if(args[0] instanceof Integer){ checkAccountNumber((Integer)args[0]); } } // implementation of Advice public boolean checkAccountNumber(int accountNumber) { System.out.println("Checking Account Number :" +accountNumber); return true; } }
Code:<?xml version="1.0" encoding="UTF-8"?> <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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <aop:aspectj-autoproxy/> <bean id="myService" class="com.bnp.ivision.product.lc.sessionejb.LCSessionBean" /> <bean id="serviceLayerExceptionBarrier" class="com.bnp.ivision.spring.AspectJAdvice" /> <aop:config> <aop:pointcut id="facadeOperation" expression="target(com.bnp.ivision.product.lc.sessionejb.LCSession)" /> <aop:aspect id="myAspect" ref="serviceLayerExceptionBarrier"> <aop:before method="testAdvice" pointcut-ref="facadeOperation" /> <aop:after-throwing pointcut-ref="facadeOperation" throwing="t" method="testAdviceThrow" /> </aop:aspect> </aop:config> <bean id="myServiceFacade" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"> <property name="jndiName" value="LCSession" /> <property name="businessInterface" value="com.bnp.ivision.product.lc.sessionejb.LCSession" /> </bean> </beans>
Is it possible to advise EJBs? If yes,how?


Reply With Quote
