Could not autowire field: can't to com.sun.proxy.$Proxy22

不羁岁月 提交于 2019-12-07 07:01:06

问题


Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.cms.service.FolderService com.cms.action.BaseAction.folderService; nested exception is java.lang.IllegalArgumentException: Can not set com.cms.service.FolderService field com.cms.action.BaseAction.folderService to com.sun.proxy.$Proxy22
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:518)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    ... 30 more
Caused by: java.lang.IllegalArgumentException: Can not set com.cms.service.FolderService field com.cms.action.BaseAction.folderService to com.sun.proxy.$Proxy22
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
    at java.lang.reflect.Field.set(Field.java:657)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
    ... 32 more

this is my baseAction

public class BaseAction {

    @Autowired
    protected FolderService folderService;

    @Autowired
    protected ArticleService fileService;

    @Autowired
    protected TemplateService themeService;

    @Autowired
    protected HeadlineService headlineService;

    protected final Logger logger = Logger.getLogger(this.getClass());
}

and that's my FolderService

@Service
public class FolderService {

    protected final Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private FolderDao folderDao;

    @Autowired
    private AdminFolderDao adminFolderDao;

 ...................next is the java method

}

回答1:


Usually this means there is an AOP proxy delegating to your bean. For example, if you have annotated one of your methods with @Transaction.




回答2:


Forcing aop to wave by using cglib proxies by configuring

spring.aop.proxy-target-class=true

helps.

Refer this article for more information




回答3:


Move @Transaction from your DAO object to the Service object.



来源:https://stackoverflow.com/questions/27540355/could-not-autowire-field-cant-to-com-sun-proxy-proxy22

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!