hi
i try to use spring interceptor
applicationContext.xml
Code:<bean id="userAdminDao" class="com.server.admin.UserAdminImpl"> <property name="userDao" ref="adminJdbcDao"/> </bean> <bean id="securityInterceptor" class="com.server.admin.SecurityInterceptor"></bean> <bean id="interceptedService" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target"> <ref bean="userAdminDao"/> </property> <property name="interceptorNames"> <list> <value>securityInterceptor</value> </list> </property> </bean>
interceptor code
my test classCode:public class SecurityInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation methodInvocation) throws Throwable { long startTime = System.currentTimeMillis(); Object result = methodInvocation.proceed(); long duration = System.currentTimeMillis() - startTime; Method method = methodInvocation.getMethod(); String methodName = method.getDeclaringClass().getName() + "." + method.getName(); System.out.println("Method '" + methodName + "' took " + duration + " milliseconds to run"); return null; } }
i don't see the output of the SecurityInterceptor,so it's not executed..Code:public class MonServiceTest extends TestCase { public void testMonService() { ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); UserAdminImpl userAdmin = (UserAdminImpl) context.getBean("userAdminDao"); userAdmin.getUser("4"); } }
any idea?


Reply With Quote
.
