我正在尝试在Spring项目中使用@Async
注释。为此,我将此行添加到我的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)
,但正如您所见,它的存在并不重要。
答案 0 :(得分:1)
如果使用CGLIB代理将方面应用于类,则需要不带参数的构造函数。试试这样的事情:
@Controller
public class LinkedInController {
private static final Logger logger = LoggerFactory.getLogger(LinkedInController.class);
@Inject
private final LinkedIn linkedIn;
public LinkedInController() {
logger.info("Initialisation du controleur 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);
}
}