一入此坑,只想跳楼。我发誓应该不会有第二个人会进这种坑!

问题描述:

  总是不能注入dao层,即@Resposity。always!always!always!(尝试了天下之因特网所有的注入方式,都不能尽我之意!)

原错误代码:

-- ::14.559 ERROR [RMI TCP Connection()-127.0.0.1] ContextLoader.initWebApplicationContext() | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gameChatService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.longyuan.dao.GameChatDao com.longyuan.service.GameChatServiceImpl.gameChatDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.longyuan.dao.GameChatDao] found for dependency: expected at least bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory$.getObject(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
-May- ::14.562 SEVERE [RMI TCP Connection()-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
-May- ::14.564 SEVERE [RMI TCP Connection()-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.access$(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at sun.rmi.transport.Transport$.run(Transport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$(TCPTransport.java:)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:)
at java.lang.Thread.run(Thread.java:)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.longyuan.dao.GameChatDao com.longyuan.service.GameChatServiceImpl.gameChatDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.longyuan.dao.GameChatDao] found for dependency: expected at least bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:)
... more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.longyuan.dao.GameChatDao] found for dependency: expected at least bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:)
... more
[-- ::,] Artifact gameml:war exploded: Error during artifact deployment. See server log for details.
-May- ::21.604 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Program Files\tomcat\webapps\manager
-May- ::21.675 INFO [localhost-startStop-] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Program Files\tomcat\webapps\manager has finished in ms

原因:

  先写吐槽心得:下次遇到这种坑爹奇葩问题,直接删除工程重写!

正文:

  

  就是这玩意儿!!! Excludes--我只想f**k你!100遍!!!

  好的,回到正常人。在一不小心点的时候把这个类弄成compiler exludes,然后就没有然后了。

再补一个异常再现:

  

可以看到target中并没有GameChatDaoImpl.class!

解决办法:

  在编译器中找到setting--》Compiler--》Excludes:去掉该类即ok!

以此铭记!再见。

    记于2016.05.19.17:14:25

旷世奇坑!!!spring 不能自动注入的更多相关文章

  1. 关于spring的自动注入

    关于spring的自动注入 spring里面可以设置BeanDefinition自动注入类型,默认为AUTOWIRE_NO(不进行自动注入).mybatis里面的扫描接口生成MapperFactory ...

  2. spring bean自动注入

    使用 @Repository.@Service.@Controller 和 @Component 将类标识为 Bean Spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的 ...

  3. SSM-Spring-06:Spring的自动注入autowire的byName和byType

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- di的注入上次讲了一些,这次主要阐述域属性的自动注入 先讲byType方式 看名字就知道是根据类型进行自动注入 ...

  4. Spring 完成自动注入(autowire)

    目录 两个测试类 普通方式手动注入 普通方式注入的缺点 自动注入的介绍 配置自动注入的方式 配置全局自动注入 局部单独配置 利用注解实现自动注入 两个测试类 package cn.ganlixin.p ...

  5. 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

    搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...

  6. spring学习 十五 spring的自动注入

    一  :在 Spring 配置文件中对象名和 ref=”id” ,id 名相同使用自动注入,可以不配置<property/>,对应的注解@Autowired的作用 二: 两种配置办法 (1 ...

  7. Spring -08 -自动注入 -byName/byType/constructor -全局使用default-autowire=” byName"

    1.在Spring 配置文件中对象名和ref=”id”id 名相同使用自动注入,可以不配置<property/>2.两种配置办法 2.1在<bean>中通过 autowire= ...

  8. spring拦截器中使用spring的自动注入

    需要在spring的拦截器中使用自定义的服务,这要就设计到将服务注入到拦截器中.网上看的情况有两种: 1. @Configuration public class OptPermissionHandl ...

  9. spring AutowireCapableBeanFactory 自动注入

    文档:http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/config/Auto ...

随机推荐

  1. μC/OS-Ⅲ系统的任务挂起表

    在μC/OS-Ⅲ系统中任务挂起表与任务就续表十分相似,只不过任务就续表记录就绪状态的任务,任务挂起表记录等待某个内核对象的任务.任务挂起表是一个类型为OS_PEND_LIST的数据结构,包含三个成员: ...

  2. everthing 添加右键菜单

    Tool --> Options --> General -->勾上 Show folder context menus

  3. linux 安装python-setuptools

    > wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py > python ez_setup.py --ins ...

  4. SpringMVC 视图和视图解析器&表单标签

    视图和视图解析器 请求处理方法执行完成后,最终返回一个 ModelAndView 对象.对于那些返回 String,View 或 ModeMap 等类型的处理方法,Spring MVC 也会在内部将它 ...

  5. 使用 VS2005 通过按钮自动上传文件到Linux

    首先去官网下载 winscp,官网地址:http://winscp.net/eng/download.php 因为我这里是做自动上传工具,所以我只下载了精简版的:Portable executable ...

  6. 不懂指针就不要说自己学过C语言!

    不懂指针就不要说自己学过C语言! 1.掌握了指针,就掌握了C语言的精髓!计算机中绝大部分数据都放到内存中的,不同的数据放到不同的内存区域中. 内存角度没有数据类型,只有二进制:数据以字节(8位二进制) ...

  7. AJAX进行数据交互的过程

    AJAX全称为"Asynchronous JavaScript and XML"(异步JavaScript和XML). 是指一种创建交互式网页应用的网页开发技术. 通过在后台与服务 ...

  8. 通过Request对象对cookie的设置、获取

    <html> <head></head> <body> <% request.setCharacterEncoding("UTF-8&q ...

  9. Lightoj 题目1422 - Halloween Costumes(区间DP)

    1422 - Halloween Costumes   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  10. ie7 用 clearfix 清除浮动时遇到的问题

    <!doctype html> <html> <head> <style> .fr{float:right;display:inline} li{bor ...