注解@Resource奇葩报错问题解决

原创 2017年06月20日 17:51:13

一、起源

这个问题困扰我好久,前几天也遇到过,于是网上查找资料,无果,今天又是这个问题,无意操作居然好了,非常神奇,特此记录。

二、问题

六月 20, 2017 5:44:47 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportSignConR': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportSignSer': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'signMapper' must be of type [com.zs.dao.ReportSignMapper], but was actually of type [com.sun.proxy.$Proxy43]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4717)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportSignSer': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'signMapper' must be of type [com.zs.dao.ReportSignMapper], but was actually of type [com.sun.proxy.$Proxy43]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:445)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:544)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
	... 22 more
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'signMapper' must be of type [com.zs.dao.ReportSignMapper], but was actually of type [com.sun.proxy.$Proxy43]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:376)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:445)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:544)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
	... 35 more

service:

package com.zs.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.zs.dao.ReportSignMapper;
import com.zs.entity.ReportSign;
import com.zs.entity.ReportSignKey;
import com.zs.entity.other.EasyUIAccept;
import com.zs.entity.other.EasyUIPage;
import com.zs.entity.other.ReportSignBean;
import com.zs.service.ReportSignSer;

@Service("reportSignSer")
public class ReportSignSerImpl implements ReportSignSer{

	private Logger log=Logger.getLogger(getClass());
	@Resource
	private ReportSignMapper signMapper;
	
	public EasyUIPage queryFenye(EasyUIAccept accept) {
		/*if (accept!=null) {
			Integer page=accept.getPage();
			Integer size=accept.getRows();
			if (page!=null && size!=null) {
				accept.setStart((page-1)*size);
				accept.setEnd(page*size);
			}
			List list=signMapper.queryFenye(accept);
			int rows=signMapper.getCount(accept);
			return new EasyUIPage(rows, list);
		}*/
		return null;
	}

	public Integer add(ReportSign obj) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer update(ReportSign obj) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer delete(ReportSignKey id) {
		// TODO Auto-generated method stub
		return null;
	}

	public ReportSign get(ReportSignKey id) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<ReportSignBean> obtainOfCtmAndProvince(Date d1,Date d2) {
//		return signMapper.obtainOfCtmAndProvince(d1, d2);
		return null;
	}

}

三、解决

只需要把private ReportSignMapper signMapper;改为private ReportSignMapper reportSignMapper;

只要把类名复制,将首字母小写即可,谁能解释。


版权声明:本文是我的原创文章,未经我的允许不得转载,违者必究<(-︿-)>。

eclipse 中用注解的时候报错@Resource

在编辑代码时候用 alt+/ 快捷注解报错 也是同样的: 解决方法: 将Windows-Prefrences-Java-Editor-Content Assitant-Advanced...
  • m0_37614008
  • m0_37614008
  • 2017年11月17日 18:27
  • 70

Resource注解报错 javax.annotation不可见

就像图这样,前提是该有的jar包我一个不少…. 太坑,花了我好久找原因。 后面发现是我jdk版本太高了….我是用的是jdk9, 把jdk降到8就好了…未知原因。 我是小菜鸟。...
  • u013597998
  • u013597998
  • 2018年01月02日 10:24
  • 84

Spring框架中@Resource注解报错解决方案

问题:Spring框架中,@Resource注解报错,在书写时没有自动提示 解决:因为maven配置文件的pom.xml文件中缺少javax.annotation的依赖,在pom.项目路中加入依赖即可...
  • weixin_38051694
  • weixin_38051694
  • 2017年08月31日 20:47
  • 434

spring项目无法引入@Resource注解的问题处理

问题:在spring项目中引入@Resource注解的时候,有红色下划线错误,而且输入注解的时候不能出现自动代码补全。加入javax.annotation包后,出现警告。 解决办法:Spring项目...
  • ytangdigl
  • ytangdigl
  • 2017年09月01日 18:49
  • 1216

Spring项目中无法引入@Resource注解

问题:在Spring项目中引入@Resource注解的时候,有红色下划线错误,而且输入注解的时候不能出现自动代码补全。加入javax.annotation包后,出现警告。 解决办法:Spring项目中...
  • qq_20916555
  • qq_20916555
  • 2017年04月12日 14:26
  • 3377

IDEA使用 @Autowired和@Resource时报错

使用IDEA工具时使用@Resource和@Autowired自动注解bean时会显示红色,但是项目能运行 解决方法: File – Settings – Inspections。在Spring ...
  • u010679782
  • u010679782
  • 2016年08月02日 15:54
  • 7697

@Resource注解的使用

1、在spring的配置文件中导入命名空间          xmlns:context="http://www.springframework.org/schema/context"      ...
  • u011554611
  • u011554611
  • 2015年01月05日 20:17
  • 12694

使用spring @@Resource注解时遇到的问题

初次使用spring Annotation  配置IoC 在使用@Resource 是eclipse工具显示 Resource cannot be resolved to a type ...
  • longxu0872
  • longxu0872
  • 2017年02月27日 11:20
  • 343

@Resource 与 @Service注解

Spring中什么时候用@Resource,什么时候用@service 当你需要定义某个类为一个bean,则在这个类的类名前一行使用@Service("XXX"),就相当于讲这个类定义为一个be...
  • u012422446
  • u012422446
  • 2016年07月05日 10:19
  • 5060

用@Resource注解完成属性装配

前面我们讲过spring的依赖注入有两种方式: 使用构造器注入。 使用属性setter方法注入。 但其实还有一种注入方式,我们没讲,那就是使用Field注入(用于注解方式)。在详细讲解这种方式之前,我...
  • yerenyuan_pku
  • yerenyuan_pku
  • 2016年10月19日 14:03
  • 3830
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:注解@Resource奇葩报错问题解决
举报原因:
原因补充:

(最多只允许输入30个字)