j'ai pas d'erreur, mais le code d'interception n'est pas appelé
applicationContext.xml
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <bean id="userAdminDao" class="com.server.admin.logic.UserAdminImpl"> <property name="userDao" ref="adminJdbcDao"/> </bean> <bean id="securityInterceptor" class="com.server.admin.logic.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>
le code d'interception
ma classe de testCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 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; } }
une idéeCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class MonServiceTest extends TestCase { public void testMonService() { ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); UserAdminImpl userAdmin = (UserAdminImpl) context.getBean("userAdminDao"); UserInfo userInfo = userAdmin.getUser("4"); System.out.println(userInfo.getFirstName()); } }