1

我正在尝试@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),但正如您所看到的,它的存在并不重要。

4

1 回答 1

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);
    }
}
于 2013-07-16T11:28:32.870 回答