我正在尝试@Async
在我的 Spring 项目中使用注释。为此,我将此行添加到我的 servlet-config.xml :
<task:annotation-driven />
。结果,我无法再运行该项目,并且收到此错误:
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.dynamease.web.user.social.LinkedInController]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
这是我的 LinkedInController 类:
@Controller
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
public class LinkedInController {
private static final Logger logger = LoggerFactory.getLogger(LinkedInController.class);
private final LinkedIn linkedIn;
@Inject
public LinkedInController(LinkedIn linkedIn) {
logger.info("Initialisation du controleur linkedIn.");
this.linkedIn = linkedIn;
}
@RequestMapping(value = "linkedin")
public ModelAndView categorize() {
categorizeAndStore(linkedIn);
return mav;
}
@Async
public Future<Boolean> categorizeAndStore( LinkedIn source) {
// java stuff
return new AsyncResult<Boolean>(true);
}
}
我找到的解决方案是添加<aop:scoped-proxy>
或@Scope(proxyMode = ScopedProxyMode.INTERFACES)
,但正如您所看到的,它的存在并不重要。