jfaster / mango-spring-boot-starter

mango for spring boot support
Apache License 2.0
31 stars 12 forks source link

如何在Controller中使用注解实例化dao #3

Open itzuimao opened 5 years ago

itzuimao commented 5 years ago

MyBatis可以通过如下代码注解自动实例化对象,请问mango如何实现相同的写法

@Resource
ArticleDao articleDao;
fang-yan-peng commented 5 years ago

把dao所在的包路径配置上,会自动扫描包下的dao并注入到spring中 mango: scan-package: com.test.dao

itzuimao commented 5 years ago

非常感谢您能在百忙之中抽空回答我的问题,问题原因已经找到,是我代码写法的问题,与框架无关。 我的代码是

@Resource
NewArticleDao articleDao;

提示

Description:

The bean 'articleDao' could not be injected as a 'cn.shiche.web.dao.NewArticleDao' because it is a JDK dynamic proxy that implements:

Action:

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.

代码的正确写法应该是

@Resource
NewArticleDao newArticleDao;