spring aop 注解怎么实现给某个类的指定方法加@After呢 Spring aop 注解方式怎么获得执行了目标的某个方法
spring aop before \u548cafter \u600e\u4e48\u5224\u65ad\u662f\u4e00\u4e2a\u51fd\u6570spring aop before \u548cafter \u600e\u4e48\u5224\u65ad\u662f\u4e00\u4e2a\u51fd\u6570
\u6211\u7684\u7a0b\u5e8f\u6ca1\u6709\u56de\u8c03 -(void)reverseGeocodingSearch:(MAReverseGeocodingSearchOption*)geoCodingSearchOption Result:(MAReverseGeocodingSearchResult*)result\u65b9\u6cd5\uff1f\u8fd9\u4e2a\u662f\u9ad8\u5fb7\u5730\u56fe\u91cc\u7684\u9006\u5730\u7406\u67e5\u8be2\u7684\u56de\u8c03\u51fd\u6570\u3002
\u5177\u4f53\u8bf4\u660e\uff1a\u6211\u5229\u7528CoreLocatio\u4e0b\u7684locManager=[[CLLocationManager alloc]init];
// locManager.delegate=self;
// locManager.desiredAccuracy=kCLLocationAccuracyBest;
// locManager.distanceFilter=5.0f;
// [locManager startUpdatingLocation];
\u65b9\u6cd5\u83b7\u53d6\u5f53\u524d\u4f4d\u7f6e\u7684\u7ecf\u7eac\u5ea6\uff0c\u7136\u540e\u7528
MASearch *maSearch=[[MASearch alloc]init];
MAReverseGeocodingSearchOption *searchOption=[[MAReverseGeocodingSearchOption alloc]init];
searchOption.config=@"SPAS";
searchOption.x=self.klatitude;
searchOption.y=self.klongitude;
[maSearch reverseGeocodingSearchWithOption:searchOption];\u65b9\u6cd5\u9006\u5730\u7406\u7f16\u7801\u83b7\u53d6\u5f53\u524d\u57ce\u5e02\u7684\u540d\u5b57
private void beforeTransationHandle(JoinPoint point) throws Exception{
//\u62e6\u622a\u7684\u5b9e\u4f53\u7c7b
Object target = point.getTarget();
//\u62e6\u622a\u7684\u65b9\u6cd5\u540d\u79f0
String methodName = point.getSignature().getName();
//\u62e6\u622a\u7684\u65b9\u6cd5\u53c2\u6570
Object[] args = point.getArgs();
//\u62e6\u622a\u7684\u653e\u53c2\u6570\u7c7b\u578b
Class[] parameterTypes = ((MethodSignature)point.getSignature()).getMethod().getParameterTypes();
Method m = null;
try {
//\u901a\u8fc7\u53cd\u5c04\u83b7\u5f97\u62e6\u622a\u7684method
m = target.getClass().getMethod(methodName, parameterTypes);
//\u5982\u679c\u662f\u6865\u5219\u8981\u83b7\u5f97\u5b9e\u9645\u62e6\u622a\u7684method
if(m.isBridge()){
for(int i = 0; i < args.length; i++){
//\u83b7\u5f97\u6cdb\u578b\u7c7b\u578b
Class genClazz = GenericsUtils.getSuperClassGenricType(target.getClass());
//\u6839\u636e\u5b9e\u9645\u53c2\u6570\u7c7b\u578b\u66ff\u6362parameterType\u4e2d\u7684\u7c7b\u578b
if(args[i].getClass().isAssignableFrom(genClazz)){
parameterTypes[i] = genClazz;
}
}
//\u83b7\u5f97parameterType\u53c2\u6570\u7c7b\u578b\u7684\u65b9\u6cd5
m = target.getClass().getMethod(methodName, parameterTypes);
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
应该给你要测试的方法加上@Test就可以了
扩展阅读:spring aop 实现原理 ... spring aop执行原理 ... spring aop ioc ... spring aop实例讲解 ... apple 15 pro max ... spring aop注解及作用 ... spring boot aop注解 ... spring aop理解 ... spring aop解决了什么问题 ...