执行AspectJ切入点时遇到问题。我的方面是:
@Component
@Aspect
public class UploadToDefaultAspect {
private static Logger logger = Logger.getLogger(UploadToDefaultAspect.class);
private Sardine sardine;
private String webCloudDataDir;
@Autowired private ConfigurationFactory configuration;
@Autowired private GeoProcessorDAO geoService;
@PostConstruct
private void init() {
webCloudDataDir = configuration.getConfigurationValue(DEFAULT_CLOUD_LOCATION) + DIR_CLOUD_DATA;
}
@AfterReturning(
pointcut = "execution(* web.service.SystemService.uploadGeoTZCSV(..))",
returning = "country")
public void uploadAfterReturning( Country country ) throws CloudException {
// upload stuff
}
}
web.service.SystemService是一个包含uploadGeoTZCSV:
等几种方法的接口Country uploadGeoTZCSV( MultipartFile geoTZFile ) throws CSVUploadException;
当我调试uploadGeoTZCSV时它可以正常工作但是方法根本不调用(它由Spring管理,我在日志中看到了init()的调用)。我也在applicationContext.xml中配置了aop:
<aop:aspectj-autoproxy proxy-target-class="true"/>
Spring 4.2.3.RELEASE,AspectJ 1.8.7:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
我哪里错了?
谢谢。
更新1 。当我将AOP配置移动到XML时,它也不起作用:
<aop:aspectj-autoproxy/>
<!-- AOP beans -->
<bean id="uploadToDefaultAspect" class="web.aop.UploadToDefaultAspect" init-method="init"/>
<aop:config>
<aop:aspect id="uploadToDefaultAspect" ref="uploadToDefaultAspect">
<!-- @AfterReturning -->
<aop:pointcut id="pointCutAfterReturning"
expression="execution(* web.service.SystemService.uploadGeoTZCSV(..))"/>
<aop:after-returning method="uploadGeoTZCSVAfterReturning" returning="country"
pointcut-ref="pointCutAfterReturning"/>
</aop:aspect>
</aop:config>
发生了什么事?
答案 0 :(得分:2)
最后,我找到了一个解决方案 - 只需将@EnableAspectJAutoProxy添加到web.service.SystemService的实现中:
@Service
@EnableAspectJAutoProxy
public class SystemServiceImpl implements SystemService {