我有一个 default-context.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">
<!-- some other beans -->
<bean id="licenseTestingAdvice" class="mypackage.LicenseTestingAdvice" />
<bean id="jdbcTemplate" class="mypackage.ProxyFactoryBean">
<property name="interceptorNames">
<list>
<idref bean="licenseTestingAdvice" />
</list>
</property>
<property name="target">
<value>mypackage.JDBCTemplate</value>
</property>
<property name="proxyTargetClass" value="true" />
</bean>
还有一个 LicenseTestingAdvice.java:
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import java.lang.reflect.Method;
public class LicenseTestingAdvice implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation inv) throws Throwable {
Method method = inv.getMethod();
System.out.println(String.format(">> Method %s was called before", method.getName()));
inv.proceed();
System.out.println(String.format(">> Method %s was called after", method.getName()));
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
当我调用 JDBCTemplate 类的 execute() 方法时,不会调用 invoke() 方法。如何解决这个问题?