0
我有一個默認的context.xmlSpring AOP的 - 方法調用()不發生
<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.
}
}
當我調用execute ()方法的JDBCTemplate類 - 不調用invoke()方法。如何解決這個問題?
好的。但是** mypackage.JDBCTemplate **有一個帶有一個參數的構造函數。我還必須將其包含到xml中。該參數是另一個類的實例等等。爲什麼我需要這個? * JDBCTemplate *類的一個實例已經從代碼創建而不使用bean。或者爲了使它工作,我需要使用bean創建一個** JDBCTemaple **實例? :-( – user470214 2012-08-09 09:49:18